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.










share|improve this question


























    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.










    share|improve this question
























      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.










      share|improve this question













      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 8 at 2:42









      acmel067

      284




      284





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          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






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          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





















































          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







          這個網誌中的熱門文章

          Tangent Lines Diagram Along Smooth Curve

          Yusuf al-Mu'taman ibn Hud

          Zucchini