reCaptchav3 implementation in iOS
up vote
0
down vote
favorite
I'm trying to implement reCaptchav3 in iOS but could not make it work. reCaptchav2 invisible works fine. I don't know what's wrong with my code.
HTML head:
<script src='https://www.google.com/recaptcha/api.js?render="SITE_KEY"'></script>
<script>
grecaptcha.ready(function() {
grecaptcha.execute('SITE_KEY', {action: 'OnSubmit'})
.then(function(token) {
// Verify the token on the server.
document.getElementById("demo-form").submit();
});
});
</script>
Button:
<div class="btn">
<button class="g-recaptcha" data-callback="OnSubmit" data-expired-callback="OnExpired" data-error-callback="OnError" type="submit" disabled="">Button is disabled</button>
</div>
iOS:
- (void)initWebkitView {
WKUserContentController *wkController = [[WKUserContentController alloc] init];
[wkController addScriptMessageHandler:self name:@"reCaptchaiOS"];
[wkController addUserScript:[self readScript]];
WKWebViewConfiguration *wkConf = [[WKWebViewConfiguration alloc] init];
[wkConf setUserContentController:wkController];
wk = [[WKWebView alloc] initWithFrame:self.view.frame
configuration:wkConf];
wk.backgroundColor = [UIColor clearColor];
wk.opaque = NO;
[wk setFrame:self.view.frame];
[self.view addSubview:wk];
}
- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message {
NSArray<NSString*> *args = (NSArray*)message.body;
if ([args[0] isEqualToString:@"OnSubmit"])
[self captchaDidSubmitted:args[1]];
else if ([args[0] isEqualToString:@"OnError"])
[self captchaDidError:args[1]];
else if ([args[0] isEqualToString:@"OnExpired"])
[self captchaDidExpired:args[1]];
}
Script added in iOS project:
function OnSubmit(response) {
window.webkit.messageHandlers.reCaptchaiOS.postMessage(["OnSubmit", response]);
}
function OnError(response) {
window.webkit.messageHandlers.reCaptchaiOS.postMessage(["OnError", response]);
}
function OnExpired(response) {
window.webkit.messageHandlers.reCaptchaiOS.postMessage(["OnExpired", response]);
}
I used the same code for reCaptchav2 and followed googles guide but I could not get a response.
ios objective-c recaptcha recaptcha-v3
add a comment |
up vote
0
down vote
favorite
I'm trying to implement reCaptchav3 in iOS but could not make it work. reCaptchav2 invisible works fine. I don't know what's wrong with my code.
HTML head:
<script src='https://www.google.com/recaptcha/api.js?render="SITE_KEY"'></script>
<script>
grecaptcha.ready(function() {
grecaptcha.execute('SITE_KEY', {action: 'OnSubmit'})
.then(function(token) {
// Verify the token on the server.
document.getElementById("demo-form").submit();
});
});
</script>
Button:
<div class="btn">
<button class="g-recaptcha" data-callback="OnSubmit" data-expired-callback="OnExpired" data-error-callback="OnError" type="submit" disabled="">Button is disabled</button>
</div>
iOS:
- (void)initWebkitView {
WKUserContentController *wkController = [[WKUserContentController alloc] init];
[wkController addScriptMessageHandler:self name:@"reCaptchaiOS"];
[wkController addUserScript:[self readScript]];
WKWebViewConfiguration *wkConf = [[WKWebViewConfiguration alloc] init];
[wkConf setUserContentController:wkController];
wk = [[WKWebView alloc] initWithFrame:self.view.frame
configuration:wkConf];
wk.backgroundColor = [UIColor clearColor];
wk.opaque = NO;
[wk setFrame:self.view.frame];
[self.view addSubview:wk];
}
- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message {
NSArray<NSString*> *args = (NSArray*)message.body;
if ([args[0] isEqualToString:@"OnSubmit"])
[self captchaDidSubmitted:args[1]];
else if ([args[0] isEqualToString:@"OnError"])
[self captchaDidError:args[1]];
else if ([args[0] isEqualToString:@"OnExpired"])
[self captchaDidExpired:args[1]];
}
Script added in iOS project:
function OnSubmit(response) {
window.webkit.messageHandlers.reCaptchaiOS.postMessage(["OnSubmit", response]);
}
function OnError(response) {
window.webkit.messageHandlers.reCaptchaiOS.postMessage(["OnError", response]);
}
function OnExpired(response) {
window.webkit.messageHandlers.reCaptchaiOS.postMessage(["OnExpired", response]);
}
I used the same code for reCaptchav2 and followed googles guide but I could not get a response.
ios objective-c recaptcha recaptcha-v3
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm trying to implement reCaptchav3 in iOS but could not make it work. reCaptchav2 invisible works fine. I don't know what's wrong with my code.
HTML head:
<script src='https://www.google.com/recaptcha/api.js?render="SITE_KEY"'></script>
<script>
grecaptcha.ready(function() {
grecaptcha.execute('SITE_KEY', {action: 'OnSubmit'})
.then(function(token) {
// Verify the token on the server.
document.getElementById("demo-form").submit();
});
});
</script>
Button:
<div class="btn">
<button class="g-recaptcha" data-callback="OnSubmit" data-expired-callback="OnExpired" data-error-callback="OnError" type="submit" disabled="">Button is disabled</button>
</div>
iOS:
- (void)initWebkitView {
WKUserContentController *wkController = [[WKUserContentController alloc] init];
[wkController addScriptMessageHandler:self name:@"reCaptchaiOS"];
[wkController addUserScript:[self readScript]];
WKWebViewConfiguration *wkConf = [[WKWebViewConfiguration alloc] init];
[wkConf setUserContentController:wkController];
wk = [[WKWebView alloc] initWithFrame:self.view.frame
configuration:wkConf];
wk.backgroundColor = [UIColor clearColor];
wk.opaque = NO;
[wk setFrame:self.view.frame];
[self.view addSubview:wk];
}
- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message {
NSArray<NSString*> *args = (NSArray*)message.body;
if ([args[0] isEqualToString:@"OnSubmit"])
[self captchaDidSubmitted:args[1]];
else if ([args[0] isEqualToString:@"OnError"])
[self captchaDidError:args[1]];
else if ([args[0] isEqualToString:@"OnExpired"])
[self captchaDidExpired:args[1]];
}
Script added in iOS project:
function OnSubmit(response) {
window.webkit.messageHandlers.reCaptchaiOS.postMessage(["OnSubmit", response]);
}
function OnError(response) {
window.webkit.messageHandlers.reCaptchaiOS.postMessage(["OnError", response]);
}
function OnExpired(response) {
window.webkit.messageHandlers.reCaptchaiOS.postMessage(["OnExpired", response]);
}
I used the same code for reCaptchav2 and followed googles guide but I could not get a response.
ios objective-c recaptcha recaptcha-v3
I'm trying to implement reCaptchav3 in iOS but could not make it work. reCaptchav2 invisible works fine. I don't know what's wrong with my code.
HTML head:
<script src='https://www.google.com/recaptcha/api.js?render="SITE_KEY"'></script>
<script>
grecaptcha.ready(function() {
grecaptcha.execute('SITE_KEY', {action: 'OnSubmit'})
.then(function(token) {
// Verify the token on the server.
document.getElementById("demo-form").submit();
});
});
</script>
Button:
<div class="btn">
<button class="g-recaptcha" data-callback="OnSubmit" data-expired-callback="OnExpired" data-error-callback="OnError" type="submit" disabled="">Button is disabled</button>
</div>
iOS:
- (void)initWebkitView {
WKUserContentController *wkController = [[WKUserContentController alloc] init];
[wkController addScriptMessageHandler:self name:@"reCaptchaiOS"];
[wkController addUserScript:[self readScript]];
WKWebViewConfiguration *wkConf = [[WKWebViewConfiguration alloc] init];
[wkConf setUserContentController:wkController];
wk = [[WKWebView alloc] initWithFrame:self.view.frame
configuration:wkConf];
wk.backgroundColor = [UIColor clearColor];
wk.opaque = NO;
[wk setFrame:self.view.frame];
[self.view addSubview:wk];
}
- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message {
NSArray<NSString*> *args = (NSArray*)message.body;
if ([args[0] isEqualToString:@"OnSubmit"])
[self captchaDidSubmitted:args[1]];
else if ([args[0] isEqualToString:@"OnError"])
[self captchaDidError:args[1]];
else if ([args[0] isEqualToString:@"OnExpired"])
[self captchaDidExpired:args[1]];
}
Script added in iOS project:
function OnSubmit(response) {
window.webkit.messageHandlers.reCaptchaiOS.postMessage(["OnSubmit", response]);
}
function OnError(response) {
window.webkit.messageHandlers.reCaptchaiOS.postMessage(["OnError", response]);
}
function OnExpired(response) {
window.webkit.messageHandlers.reCaptchaiOS.postMessage(["OnExpired", response]);
}
I used the same code for reCaptchav2 and followed googles guide but I could not get a response.
ios objective-c recaptcha recaptcha-v3
ios objective-c recaptcha recaptcha-v3
asked Nov 8 at 2:42
acmel067
284
284
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53200802%2frecaptchav3-implementation-in-ios%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown