Created
October 5, 2018 14:06
-
-
Save nbob/bcc248aef9bf7ca78e1c97f15dc719cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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