Skip to content

Instantly share code, notes, and snippets.

@nbob
Created October 5, 2018 14:06
Show Gist options
  • Save nbob/bcc248aef9bf7ca78e1c97f15dc719cc to your computer and use it in GitHub Desktop.
Save nbob/bcc248aef9bf7ca78e1c97f15dc719cc to your computer and use it in GitHub Desktop.
import UIKit
import ReCaptcha
class ViewController: UIViewController {
private struct Constants {
static let webViewTag = 123
static let testLabelTag = 321
}
private var recaptcha: ReCaptcha!
private var locale: Locale = Locale(identifier: "ru_RU")
private var endpoint = ReCaptcha.Endpoint.default
override func viewDidLoad() {
super.viewDidLoad()
do {
try recaptcha = ReCaptcha(apiKey: "6LfKP3IUAAAAAK6kaATeyQNqOfhowRy8UyVP4qYY", baseURL: URL(string: "https://www.google.com/recaptcha/api.js"), endpoint: endpoint, locale: locale)
} catch {
print(error)
}
recaptcha.configureWebView { [weak self] webview in
webview.frame = self?.view.bounds ?? CGRect.zero
webview.tag = Constants.webViewTag
webview.backgroundColor = UIColor.red
self?.view.viewWithTag(Constants.testLabelTag)?.removeFromSuperview()
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 1, height: 1))
label.tag = Constants.testLabelTag
label.accessibilityLabel = "webview"
self?.view.addSubview(label)
print("hello")
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func printHello(sender: AnyObject) {
let res = recaptcha.validate(on: view) { [weak self] (result: ReCaptchaResult) in
let a = try? result.dematerialize()
print("grecaptcha result is", a)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment