ReCaptcha

public class ReCaptcha
extension ReCaptcha: ReactiveCompatible
  • 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

    baseURL

    The base URL sent to the ReCaptcha init

    endpoint

    The ReCaptcha endpoint to be used.

    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()
  • Provides a closure to be notified when the webview finishes loading JS resources.

    The closure may be called multiple times since the resources may also be loaded multiple times in case of error or reset. This may also be immediately called if the resources have already finished loading when you set the closure.

    Declaration

    Swift

    public func didFinishLoading(_ closure: (() -> Void)?)

    Parameters

    closure

    A closure that is called when the JS bundle finishes loading.

Development

  • Forces the challenge widget to be explicitly displayed.

    Declaration

    Swift

    public var forceVisibleChallenge: Bool { get set }
  • 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 { get set }