-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: don't emit sessionTimeout once result.dematerialize is called
- Loading branch information
Showing
6 changed files
with
132 additions
and
53 deletions.
There are no files selected for viewing
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
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
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
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
45 changes: 45 additions & 0 deletions
45
HCaptcha/Classes/HCaptchaWebViewManager+WKNavigationDelegate.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// HCaptchaWebViewManager+WKNavigationDelegate.swift | ||
// HCaptcha | ||
// | ||
// Copyright © 2024 HCaptcha. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import WebKit | ||
|
||
extension HCaptchaWebViewManager: WKNavigationDelegate { | ||
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, | ||
decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) { | ||
if navigationAction.targetFrame == nil, let url = navigationAction.request.url, urlOpener.canOpenURL(url) { | ||
urlOpener.openURL(url) | ||
} | ||
decisionHandler(WKNavigationActionPolicy.allow) | ||
} | ||
|
||
/// Tells the delegate that an error occurred during navigation. | ||
func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) { | ||
Log.debug("WebViewManager.webViewDidFail with \(error)") | ||
completion?(HCaptchaResult(self, error: .unexpected(error))) | ||
} | ||
|
||
/// Tells the delegate that an error occurred during the early navigation process. | ||
func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) { | ||
Log.debug("WebViewManager.webViewDidFailProvisionalNavigation with \(error)") | ||
completion?(HCaptchaResult(self, error: .unexpected(error))) | ||
} | ||
|
||
/// Tells the delegate that the web view’s content process was terminated. | ||
func webViewWebContentProcessDidTerminate(_ webView: WKWebView) { | ||
Log.debug("WebViewManager.webViewWebContentProcessDidTerminate") | ||
let kHCaptchaErrorWebViewProcessDidTerminate = -1 | ||
let kHCaptchaErrorDomain = "com.hcaptcha.sdk-ios" | ||
let error = NSError(domain: kHCaptchaErrorDomain, | ||
code: kHCaptchaErrorWebViewProcessDidTerminate, | ||
userInfo: [ | ||
NSLocalizedDescriptionKey: "WebView web content process did terminate", | ||
NSLocalizedRecoverySuggestionErrorKey: "Call HCaptcha.reset()"]) | ||
completion?(HCaptchaResult(self, error: .unexpected(error))) | ||
didFinishLoading = false | ||
} | ||
} |
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