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 the captcha

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

Method parameters:

Parameter

Required

Type

Description

url

SDK reference for iOS

URL

The link for launching the captcha widget in your application's frontend, received in the link parameter in the response of the GET /captchaNotRobot.createSession method. Contains a session token and metadata:

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

Example of a configuration call:

VKCaptchaConfiguration(url: captchaUrl)

Display the captcha

The VKCaptcha.getCaptchaViewController(completion:) method displays the captcha to the user in an iOS application. The captcha is displayed as a UIViewController and is integrated 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

Example of a method call:

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

Close the 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 the captcha closing animation. Default value is true

completion

SDK reference for iOS

() -> Void

Callback function called after the captcha is closed

Example of a method call:

captcha.closeCaptcha(animated: true) {    print("Captcha closed")}
Was this article helpful?