This page explains how to enable and customize the reCAPTCHA Enterprise API in your iOS app. For more information about reCAPTCHA Enterprise, see the reCAPTCHA Enterprise overview.
Before you begin
- Complete the steps in the Quickstart to gain access to the API.
- Ask your sales representative to grant you access to the reCAPTCHA Enterprise CocoaPods repository and the download page.
Prepare your development environment
- Download and install the latest version of Xcode.
- Download and install CocoaPods.
Download the SDK through CocoaPods
- Generate a git cookie by following these instructions.
Add the following lines to your Podfile:
source "https://cpdc-eap.googlesource.com/RecaptchaEnterprise.git" source "https://github.com/CocoaPods/Specs.git" pod "RecaptchaEnterprise", "16.0.3"
Run
pod update
. This will take care of installing all required dependencies.
Download the SDK without CocoaPods
If you don't use CocoaPods, you can get the SDK binary directly in the download page.
Configure your app
Before starting your integration you need to create a reCAPTCHA iOS Key.
If your app is written in Swift, create an Objective-C bridging header and include the following import:
#import <recaptcha/recaptcha.h>
Make sure
-ObjC
is listed on your linker flags:
Settings | Setting Name | Value |
---|---|---|
Target > Build Settings > All > Linking | Other Linker Flags | -ObjC |
App integration
Create a sample app
- In XCode create a new blank iOS single view application.
- Instrument your sample project to integrate with CocoaPods and then with reCAPTCHA Enterprise.
Create the application
Step #1: Update ViewController.swift
Instantiate the SDK using:
let recaptchaClient = RecaptchaClient(siteKey: "SomeSiteKey")
Make sure to replace SomeSiteKey with the Key you created earlier.
Create a method that calls
execute
and retrieves a reCAPTCHA token:recaptchaClient.execute(RecaptchaAction(action: .login)).then { token in print("got token: \(token.recaptchaToken)") }.catch { error in print("got error: \(error)") }
Step #2: Create a button to call reCAPTCHA
To trigger the code you just embedded in ViewController.swift
, do the following:
- In the storyboard create a button.
- Link the button's action to the execute method created in the previous step.
Step #3: Test
To test your application:
- Clean your Xcode build environment. In the Product menu, click Clean Build Folder.
- To run the application, from the Product menu, click Run.
- In your loaded application click the reCAPTCHA button created earlier.
- Observe your debug output window, it should return a reCAPTCHA token (alpha-numeric string) if the integration was done correctly.
Create an Assessment
To validate the reCAPTCHA response token, follow the instructions to create an Assessment.
iOS API reference
Consult the api reference page.