Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[W3I] Redirects fix #1069

Merged
merged 1 commit into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class Web3InboxViewController: UIViewController {
}

@objc func refreshTapped() {
webView?.reload()
Web3Inbox.instance.reload()
}

@objc func getUrlPressed(_ sender: UIBarItem) {
Expand Down
4 changes: 4 additions & 0 deletions Sources/Web3Inbox/Web3InboxClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public final class Web3InboxClient {
public func register(deviceToken: Data) async throws {
try await notifyClient.register(deviceToken: deviceToken)
}

public func reload() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have it as a public method?
For sample app make sense to reload but does it during integration?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let leave it for now? I'm not 100% sure that logout issue totally fixed. This makes possible to recover state

webviewSubscriber.reload(webView)
}
}

// MARK: - Privates
Expand Down
19 changes: 8 additions & 11 deletions Sources/Web3Inbox/WebView/WebViewRequestSubscriber.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ final class WebViewRequestSubscriber: NSObject, WKScriptMessageHandler {
}
}
}

func reload(_ webView: WKWebView) {
webView.load(URLRequest(url: url))
}
}

extension WebViewRequestSubscriber: WKUIDelegate {
Expand All @@ -55,25 +59,18 @@ extension WebViewRequestSubscriber: WKUIDelegate {
func webView(_ webView: WKWebView, requestMediaCapturePermissionFor origin: WKSecurityOrigin, initiatedByFrame frame: WKFrameInfo, type: WKMediaCaptureType, decisionHandler: @escaping (WKPermissionDecision) -> Void) {
decisionHandler(.grant)
}

#endif
}

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)
}
}
}