Fix: Alternate endpoint not loading

Fix #17
This commit is contained in:
Flávio Caetano 2018-01-16 11:44:45 -02:00
parent 11818ab473
commit 2dd15c0845
2 changed files with 7 additions and 3 deletions

View File

@ -33,7 +33,7 @@ open class ReCaptcha: ReCaptchaWebViewManager {
fileprivate var url: String {
switch self {
case .default: return "https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit"
case .alternate: return "https://www.recaptcha.net/recaptcha/api.js"
case .alternate: return "https://www.recaptcha.net/recaptcha/api.js?onload=onloadCallback&render=explicit"
}
}
}

View File

@ -19,6 +19,11 @@ open class ReCaptchaWebViewManager {
/** The `webView` delegate object that performs execution uppon script loading
*/
fileprivate class WebViewDelegate: NSObject, WKNavigationDelegate {
struct Constants {
/// The host that loaded requests should have
static let apiURLHost = "www.google.com"
}
/// The parent manager
private weak var manager: ReCaptchaWebViewManager?
@ -46,8 +51,7 @@ open class ReCaptchaWebViewManager {
) -> Void) {
defer { decisionHandler(.allow) }
if let url = navigationAction.request.url, let host = url.host, let endpoint = manager?.endpoint,
endpoint.range(of: host) != nil {
if let url = navigationAction.request.url, url.host == Constants.apiURLHost {
activeRequests.insert(url.absoluteString)
}
}