From 68a63539a2137d8fbf78afb6b950729012dd580f Mon Sep 17 00:00:00 2001 From: Artur Guseinov Date: Wed, 30 Aug 2023 22:52:47 +0800 Subject: [PATCH] Redirects fix --- .../Web3Inbox/Web3InboxViewController.swift | 2 +- Sources/Web3Inbox/Web3InboxClient.swift | 4 ++++ .../WebView/WebViewRequestSubscriber.swift | 19 ++++++++----------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Example/WalletApp/PresentationLayer/Wallet/Web3Inbox/Web3InboxViewController.swift b/Example/WalletApp/PresentationLayer/Wallet/Web3Inbox/Web3InboxViewController.swift index 7868a8274..d79c8b4ea 100644 --- a/Example/WalletApp/PresentationLayer/Wallet/Web3Inbox/Web3InboxViewController.swift +++ b/Example/WalletApp/PresentationLayer/Wallet/Web3Inbox/Web3InboxViewController.swift @@ -31,7 +31,7 @@ final class Web3InboxViewController: UIViewController { } @objc func refreshTapped() { - webView?.reload() + Web3Inbox.instance.reload() } @objc func getUrlPressed(_ sender: UIBarItem) { diff --git a/Sources/Web3Inbox/Web3InboxClient.swift b/Sources/Web3Inbox/Web3InboxClient.swift index 0325b6991..cb81a2339 100644 --- a/Sources/Web3Inbox/Web3InboxClient.swift +++ b/Sources/Web3Inbox/Web3InboxClient.swift @@ -61,6 +61,10 @@ public final class Web3InboxClient { public func register(deviceToken: Data) async throws { try await notifyClient.register(deviceToken: deviceToken) } + + public func reload() { + webviewSubscriber.reload(webView) + } } // MARK: - Privates diff --git a/Sources/Web3Inbox/WebView/WebViewRequestSubscriber.swift b/Sources/Web3Inbox/WebView/WebViewRequestSubscriber.swift index 4add0cd58..49fc5a151 100644 --- a/Sources/Web3Inbox/WebView/WebViewRequestSubscriber.swift +++ b/Sources/Web3Inbox/WebView/WebViewRequestSubscriber.swift @@ -45,6 +45,10 @@ final class WebViewRequestSubscriber: NSObject, WKScriptMessageHandler { } } } + + func reload(_ webView: WKWebView) { + webView.load(URLRequest(url: url)) + } } extension WebViewRequestSubscriber: WKUIDelegate { @@ -55,7 +59,7 @@ extension WebViewRequestSubscriber: WKUIDelegate { func webView(_ webView: WKWebView, requestMediaCapturePermissionFor origin: WKSecurityOrigin, initiatedByFrame frame: WKFrameInfo, type: WKMediaCaptureType, decisionHandler: @escaping (WKPermissionDecision) -> Void) { decisionHandler(.grant) } - + #endif } @@ -63,17 +67,10 @@ extension WebViewRequestSubscriber: WKNavigationDelegate { func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) { - guard - let from = webView.url, - let to = navigationAction.request.url - else { return decisionHandler(.cancel) } - - if from.absoluteString.contains("/login") || to.absoluteString.contains("/login") { - decisionHandler(.cancel) - webView.load(URLRequest(url: url)) - } else { + if navigationAction.request.url == url { decisionHandler(.allow) + } else { + decisionHandler(.cancel) } } } -