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

Open external browser for target="_blank" links in wkwebview ui implementation #164

Merged
merged 2 commits into from
Mar 4, 2024
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
10 changes: 10 additions & 0 deletions Sources/AGWKWebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ class AGWKWebViewController: UIViewController, WKNavigationDelegate {

func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
if let navigationURL = navigationAction.request.url {
// Handle target="_blank" links
if (navigationAction.targetFrame == nil) {
if (UIApplication.shared.canOpenURL(navigationURL)) {
UIApplication.shared.open(navigationURL) { _ in
decisionHandler(.cancel)
}
return
}
}
// Handle redirect uri
var parts = URLComponents(url: navigationURL, resolvingAgainstBaseURL: false)
parts?.query = nil
parts?.fragment = nil
Expand Down
6 changes: 3 additions & 3 deletions Sources/WKWebViewUIImplementation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import Foundation
import UIKit

public class WKWebViewUIImplementation: NSObject, UIImplementation, AGWKWebViewControllerPresentationContextProviding {
public var modalPresentationStyle: UIModalPresentationStyle? = nil
public var navigationBarBackgroundColor: UIColor? = nil
public var navigationBarButtonTintColor: UIColor? = nil
public var modalPresentationStyle: UIModalPresentationStyle?
public var navigationBarBackgroundColor: UIColor?
public var navigationBarButtonTintColor: UIColor?

public func openAuthorizationURL(url: URL, redirectURI: URL, shareCookiesWithDeviceBrowser: Bool, completion: @escaping CompletionHandler) {
let controller = AGWKWebViewController(url: url, redirectURI: redirectURI) { url, error in
Expand Down
Loading