iOS
Overview and resources
The iOS SDK is available to developers who integrate iOS native client development and does not rely on any third-party libraries.
Environmental requirements
Item | Resources |
---|---|
Development object | Compatible with iOS 9+ |
Developing environment | Xcode 13.0+ |
System dependent | Webkit.framework |
Third-party dependency of SDK | None |
Related development resources
Item | Resources |
---|---|
Product structure process | Communication process |
SDK interface documentation | gt4-api-ref-ios or view header file comments |
Error code list | Error Code List |
Installation
Get SDK
Go to the dashboard to download the current SDK.
Import SDK
If you add SDK manually, drag the downloaded
GTCaptcha4.framework
file into the project and make sure that “Copy items” is checked in case it is needed.Please import the framework using
Linked Frameworks and Libraries
method. After draggingGTCaptcha4.framework
into the project, check whether .framework has been added toPROJECT -> Build Phases -> Linked Frameworks and Libraries
.As for
Category
in the static library,-ObjC
needs to be added toBuild Settings->Other Linker Flags
of the corresponding target.GT4Captcha4.Bundle
needs to be included in the project at the same time, otherwise, verification will fail. Drag theGTCaptcha4.Bundle
to the SDK path in the project.
Configure
As shown in the product workflow process, you need to set up Server interface in your backend first, and configure it with captchaId
and Key
you got from GeeTest dashbaord.
You need to use iOS SDK to complete the following iconfiguration:
- Use ID to set up initialization of CAPTCHA
- Start verification
- Get verification parameters and carry out secondary verification on the submitted result to avoid forgery
- Use the error proxy method to deal with problems that may be encountered during verification
Follow the GTCaptcha4SessionTaskDelegate
protocol to manage verification results and errors that may be returned.
Refer to the code samples below for integration code.
Compile and run your project
Compile your project and experience GeeTest Adaptive CAPTCHA.
Sample code
Initialization and call CAPTCHA
Import the header file for verifying the dynamic library GTCaptcha4.framework
in the project
#import <GTCaptcha4/GTCaptcha4.h> |
Integration with UIButton
- Initialization
An instance of initialization validation manager GTCaptcha4Session, which calls the registration method of GTCaptcha4Session
sample in the UIButton
initialization method to obtain registration data:
|
For other optional configuration items, see the interface or property defined in GTCaptcha4Session
.
- Call and start CAPTCHA session
Call the following method for verification after initialization is completed:
- (void)start { |
Process verification results
This verification is complete only after the verification results are verified.
You need to handle the following proxy methods after complying with the GTCaptcha4Session TaskDelegate
protocol:
- (void)gtCaptchaSession:(GTCaptcha4Session *)captchaSession didReceive:(NSString *)code result:(NSDictionary *)result message:(NSString *)message { |
Handle verification errors
Some unexpected errors may occur, which you can handle in the following proxy methods by complying with the GTCaptcha4SessionTaskDelegate
protocol:
- (void)gtCaptchaSession:(GTCaptcha4Session *)captchaSession didReceiveError:(GTC4Error *)error { |
It is strongly recommended to present both an error message and error code to the end user. This will facilitate subsequent troubleshooting.
Please refer to the following list for possible error codes: GTC4Error
Swift example
For more example details, please refer to the official Demo, and please refer to the DefaultDemoViewController.swift
file in the Demo for Swift example code.