ReCaptcha

public class ReCaptcha
  • The JS API endpoint to be loaded onto the HTML file.

    See more

    Declaration

    Swift

    public enum Endpoint
  • Initializes a ReCaptcha object

    Both apiKey and baseURL may be nil, in which case the lib will look for entries of ReCaptchaKey and ReCaptchaDomain, respectively, in the project’s Info.plist

    A key may be aquired here: https://www.google.com/recaptcha/admin#list

    Throws

    ReCaptchaError.htmlLoadError: if is unable to load the HTML embedded in the bundle.

    Throws

    ReCaptchaError.apiKeyNotFound: if an apiKey is not provided and can’t find one in the project’s Info.plist.

    Throws

    ReCaptchaError.baseURLNotFound: if a baseURL is not provided and can’t find one in the project’s Info.plist.

    Throws

    Rethrows any exceptions thrown by String(contentsOfFile:)

    Declaration

    Swift

    public convenience init(
            apiKey: String? = nil,
            baseURL: URL? = nil,
            endpoint: Endpoint = .default,
            locale: Locale? = nil
        ) throws

    Parameters

    apiKey

    The API key sent to the ReCaptcha init

    infoPlistKey

    The API key retrived from the application’s Info.plist

    baseURL

    The base URL sent to the ReCaptcha init

    infoPlistURL

    The base URL retrieved from the application’s Info.plist

    locale

    A locale value to translate ReCaptcha into a different language

  • Starts the challenge validation

    Declaration

    Swift

    public func validate(on view: UIView, resetOnError: Bool = true, completion: @escaping (ReCaptchaResult) -> Void)

    Parameters

    view

    The view that should present the webview.

    resetOnError

    If ReCaptcha should be reset if it errors. Defaults to true.

    completion

    A closure that receives a ReCaptchaResult which may contain a valid result token.

  • Stops the execution of the webview

    Declaration

    Swift

    public func stop()
  • Provides a closure to configure the webview for presentation if necessary.

    If presentation is required, the webview will already be a subview of presenterView if one is provided. Otherwise it might need to be added in a view currently visible.

    Declaration

    Swift

    public func configureWebView(_ configure: @escaping (WKWebView) -> Void)

    Parameters

    configure

    A closure that receives an instance of WKWebView for configuration.

  • Resets the ReCaptcha.

    The reset is achieved by calling grecaptcha.reset() on the JS API.

    Declaration

    Swift

    public func reset()
  • Forces the challenge widget to be explicitly displayed.

    Declaration

    Swift

    public var forceVisibleChallenge: Bool
  • Allows validation stubbing for testing

    When this property is set to true, every call to validate() will immediately be resolved with .token("").

    Use only when testing your application.

    Declaration

    Swift

    public var shouldSkipForTests: Bool