VK Cloud logo

SDK reference for iOS

System requirements

  • iOS version 12 and above;
  • Xcode version 16.2 and above;
  • Swift Package Manager version 5.9 and above;
  • CocoaPods version 1.13 and above.

Initialize captcha

The configuration object VKCaptchaConfiguration(url:) passes the link to launch the captcha widget, received in the link parameter in the response of method GET /captchaNotRobot.createSession.

Method parameters:

Parameter

Required

Type

Description

url

SDK reference for iOS

URL

Link to launch the captcha widget in your application frontend, received in the link parameter in the response of method GET /captchaNotRobot.createSession. Contains the session token and metadata:

  • domain — domain where the captcha will be used;
  • session_token — session token;
  • variant — captcha display type (block or popup)

Configuration call example:

VKCaptchaConfiguration(url: captchaUrl)

Display captcha

The VKCaptcha.getCaptchaViewController(completion:) method displays the captcha to the user in an iOS application. The captcha is displayed as UIViewController and integrates into the application navigation.

Method parameters:

Parameter

Required

Type

Description

completion

SDK reference for iOS

(Result<String, Error>) -> Void

Callback function with the captcha completion result:

  • success(token) — token of successful captcha completion;
  • failure(error) — error if the user closed the captcha window

Method call example:

captcha.getCaptchaViewController { [weak self] result in   switch result {      case .success(let token):         self?.repeatRequest(with: token)      case .failure:              // Handling captcha closure              break   }

Close captcha

The VKCaptcha.closeCaptcha(animated:completion:) method closes the captcha widget.

Method parameters:

Parameter

Required

Type

Description

animated

SDK reference for iOS

boolean

Flag for captcha closing animation. Default value is true

completion

SDK reference for iOS

() -> Void

Callback function after closing the captcha

Method call example:

captcha.closeCaptcha(animated: true) {    print("Captcha closed")}