Go to file
Flávio Caetano d0e74a8d02 Fix: Running Fastlane with a single device 2017-11-13 16:42:39 -02:00
Example Version bump 2017-11-01 22:59:28 -02:00
ReCaptcha Feature: Swiftlint 2017-10-31 13:36:09 -02:00
ReCaptcha-Carthage Carthage support 2017-10-19 10:42:34 -02:00
ReCaptcha-Carthage.xcodeproj Fixing Travis builds & deployment 2017-10-31 13:35:57 -02:00
ReCaptcha_RxSwift Carthage support 2017-10-19 10:42:34 -02:00
fastlane Fix: Running Fastlane with a single device 2017-11-13 16:42:39 -02:00
.gitignore Fix: Running Fastlane with a single device 2017-11-13 16:42:39 -02:00
.gitmodules Fix: Running Fastlane with a single device 2017-11-13 16:42:39 -02:00
.swift-version Swift 4 compliance 2017-10-31 15:53:06 -02:00
.swiftlint.yml Feature: Fastlane 2017-10-31 13:36:15 -02:00
.travis.yml Fix: Running Fastlane with a single device 2017-11-13 16:42:39 -02:00
CHANGELOG.md Version bump 2017-11-01 22:59:28 -02:00
Cartfile Swift 4 compliance 2017-10-31 15:53:06 -02:00
Cartfile.resolved Swift 4 compliance 2017-10-31 15:53:06 -02:00
Gemfile Feature: Fastlane 2017-10-31 13:36:15 -02:00
Gemfile.lock Feature: Fastlane 2017-10-31 13:36:15 -02:00
LICENSE Feature: Swiftlint 2017-10-31 13:36:09 -02:00
README.md Fixing Travis builds & deployment 2017-10-31 13:35:57 -02:00
ReCaptcha.podspec Version bump 2017-11-01 22:59:28 -02:00
_Pods.xcodeproj Initial code 2017-04-11 15:00:44 -03:00
codecov.yml Feature: Fastlane 2017-10-31 13:36:15 -02:00
example.gif Adding gif to README 2017-04-18 15:54:02 -03:00
example2.gif Adding new example gif 2017-07-14 11:48:52 -04:00
pre-push.sh Fix: Running Fastlane with a single device 2017-11-13 16:42:39 -02:00

README.md

ReCaptcha

Build Status Version License Platform codecov Carthage compatible


Add Google's Invisible ReCaptcha to your project. This library automatically handles ReCaptcha's events and retrieves the validation token or notifies you to present the challenge if invisibility is not possible.

Example Gif 2 Example Gif

Warning ⚠️

Beware that this library only works for Invisible ReCaptcha keys! Make sure to check the Invisible reCAPTCHA option when creating your API Key.

Installation

ReCaptcha is available through CocoaPods and Carthage. To install it, simply add the following line to your depedencies file:

Cocoapods

pod "ReCaptcha"
# or
pod "ReCaptcha/RxSwift"

Carthage

github "fjcaetano/ReCaptcha"

Carthage will create two different frameworks named ReCaptcha and ReCaptcha_RxSwift, the latter containing the RxSwift extension for the ReCaptcha framework.

Usage

Simply add ReCaptchaKey and ReCaptchaDomain to your Info.plist and run:

let recaptcha = try? ReCaptcha()

override func viewDidLoad() {
    super.viewDidLoad()

    recaptcha?.configureWebView { [weak self] webview in
        webview.frame = self?.view.bounds ?? CGRect.zero
    }
}


func validate() {
    recaptcha?.validate(on: view) { [weak self] result in
        print(try? result.dematerialize())
    }
}

You can also install the reactive subpod and use it with RxSwift:

recaptcha.rx.validate(on: view)
    .map { try $0.dematerialize() }
    .subscribe(onNext: { (token: String) in
        // Do something
    })

Alternte endpoint

If your app has firewall limitations that may be blocking Google's API, the JS endpoint may be changed on initialization. It'll then point to https://www.recaptcha.net/recaptcha/api.js:

public enum Endpoint {
    case default, alternate
}

let recaptcha = try? ReCaptcha(endpoint: .alternate) // Defaults to `default` when unset

License

ReCaptcha is available under the MIT license. See the LICENSE file for more info.