swiftrecaptcha-enterprise

While initialising reCAPTCHA Enterprise in ios app i'm getting unrecognized selector sent to instance 0x2833a81e0 error


I'm trying to integrate recaptcha enterprice sdk in my ios app, built with swift. I followed the documentation mentioned here. https://cloud.google.com/recaptcha-enterprise/docs/instrument-ios-apps#swift.

I have imported the recaptcha-enterprise-mobile-sdk for ios using Swift Package Manager. the package url mentioned in the docs was https://github.com/GoogleCloudPlatform/recaptcha-enterprise-mobile-sdk.

When i try to run this block of code.

let (recaptchaClient, error) = await Recaptcha.getClient(siteKey: key)
if let recaptchaClient = recaptchaClient {
  self.recaptchaClient = recaptchaClient
}
if let error = error {
  print("RecaptchaClient creation error: \(error.errorMessage ?? "NIL").");
}

I'm getting these errors,

2023-04-14 12:55:20.351476+0530 Runner[2442:667659] -[RCAx_GPBTimestamp initWithTimeIntervalSince1970:]: unrecognized selector sent to instance 0x28191c000
2023-04-14 12:55:20.352389+0530 Runner[2442:667659] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RCAx_GPBTimestamp initWithTimeIntervalSince1970:]: unrecognized selector sent to instance 0x28191c000'
*** First throw call stack:
(0x1cbdbba84 0x1ca20d958 0x1cbf1c110 0x1cbdd0c28 0x1cbe3470c 0x104bc3d74 0x104bbd91c 0x104bbda04 0x104b973a8 0x104a3c08c 0x104a3d8c4 0x104a44a20 0x104a45698 0x104a51158 0x218562b50 0x21856267c)
libc++abi: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RCAx_GPBTimestamp initWithTimeIntervalSince1970:]: unrecognized selector sent to instance 0x28191c000'
terminating with uncaught exception of type NSException
(Recorded stack frame) 

What does this error mean? how to resolve this error?

error was thrown from this method.

Recaptcha.getClient(siteKey: key)

Solution

  • I solved it!

    Many probably skip this point: https://cloud.google.com/recaptcha-enterprise/docs/instrument-ios-apps#configure_app

    Objective - C Bridging Header

    You need

    1. create an Objective-C bridging header and include the following import

    To create a bridging header in your Swift project and include an import for Objective-C code, follow these steps:

    1. In Xcode, create a new header file by going to File -> New -> File (or press Command+N).

    2. Select "Header File" under the "Source" section and click "Next". Name the file "YourProjectName-Bridging-Header" (replace "YourProjectName" with the actual name of your project) and save it in your project's directory.

    3. In your project's build settings, search for "Objective-C Bridging Header" and set the value to the path of your bridging header file. For example, "YourProjectName/YourProjectName-Bridging-Header.h".

    4. Open the bridging header file you created and import the Objective-C code by adding the following line:

    #import <RecaptchaEnterprise/RecaptchaEnterprise.h>

    Simple Bridging Header file

    Now you can access your Objective-C code from your Swift files. Make sure to import the necessary headers in your Objective-C file as well, if needed.

    Note: If you don't see the "Objective-C Bridging Header" setting in your build settings, you may need to manually configure it by specifying the bridging header file path in the "Objective-C Bridging Header" build setting (under "Swift Compiler - General").

    Remember to replace "YourProjectName" and "YourObjectiveCFile.h" with the appropriate names for your project and Objective-C file.

    Build Setting image

    1. Ensure that -ObjC is listed on your linker flags. Navigate to Target > Build Settings > All > Linking and verify that Other Linker Flags shows -ObjC.