Skip to content

Commit

Permalink
Merge pull request #182 from phellmayr1/feat/use-preventdeepling-also…
Browse files Browse the repository at this point in the history
…-on-ios

feat: use preventDeeplink parameter also on ios
  • Loading branch information
riderx authored Aug 28, 2024
2 parents ddfa689 + ea2ee5b commit 84a170f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
8 changes: 6 additions & 2 deletions ios/Plugin/InAppBrowserPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public class InAppBrowserPlugin: CAPPlugin {
let closeModalOk = call.getString("closeModalOk", "OK")
let closeModalCancel = call.getString("closeModalCancel", "Cancel")
let isInspectable = call.getBool("isInspectable", false)
let preventDeeplink = call.getBool("preventDeeplink", false)
let isAnimated = call.getBool("isAnimated", true)

var disclaimerContent = call.getObject("shareDisclaimer")
Expand All @@ -141,10 +142,11 @@ public class InAppBrowserPlugin: CAPPlugin {
let url = URL(string: urlString)

if self.isPresentAfterPageLoad {
self.webViewController = WKWebViewController.init(url: url!, headers: headers, isInspectable: isInspectable)
self.webViewController = WKWebViewController.init(url: url!, headers: headers, isInspectable: isInspectable, preventDeeplink: preventDeeplink)
} else {
self.webViewController = WKWebViewController.init()
self.webViewController?.setHeaders(headers: headers)
self.webViewController?.setPreventDeeplink(preventDeeplink: preventDeeplink)
}

self.webViewController?.source = .remote(url!)
Expand Down Expand Up @@ -250,6 +252,7 @@ public class InAppBrowserPlugin: CAPPlugin {
}

let isInspectable = call.getBool("isInspectable", false)
let preventDeeplink = call.getBool("preventDeeplink", false)

self.currentPluginCall = call

Expand All @@ -271,10 +274,11 @@ public class InAppBrowserPlugin: CAPPlugin {
let url = URL(string: urlString)

if self.isPresentAfterPageLoad {
self.webViewController = WKWebViewController.init(url: url!, headers: headers, isInspectable: isInspectable)
self.webViewController = WKWebViewController.init(url: url!, headers: headers, isInspectable: isInspectable, preventDeeplink: preventDeeplink)
} else {
self.webViewController = WKWebViewController.init()
self.webViewController?.setHeaders(headers: headers)
self.webViewController?.setPreventDeeplink(preventDeeplink: preventDeeplink)
}

self.webViewController?.source = .remote(url!)
Expand Down
13 changes: 12 additions & 1 deletion ios/Plugin/WKWebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import WebKit
private let estimatedProgressKeyPath = "estimatedProgress"
private let titleKeyPath = "title"
private let cookieKey = "Cookie"
private let preventDeeplink: Bool = false

private struct UrlsHandledByApp {
static var hosts = ["itunes.apple.com"]
Expand Down Expand Up @@ -60,10 +61,11 @@ open class WKWebViewController: UIViewController {
self.initWebview()
}

public init(url: URL, headers: [String: String], isInspectable: Bool) {
public init(url: URL, headers: [String: String], isInspectable: Bool, preventDeeplink: Bool) {
super.init(nibName: nil, bundle: nil)
self.source = .remote(url)
self.setHeaders(headers: headers)
self.preventDeeplink = preventDeeplink
self.initWebview(isInspectable: isInspectable)
}

Expand Down Expand Up @@ -804,6 +806,11 @@ extension WKWebViewController: WKNavigationDelegate {

public func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
var actionPolicy: WKNavigationActionPolicy = .allow

if self.preventDeeplink {
actionPolicy = .preventDeeplinkActionPolicy
}

defer {
decisionHandler(actionPolicy)
}
Expand Down Expand Up @@ -838,3 +845,7 @@ class BlockBarButtonItem: UIBarButtonItem {

var block: ((WKWebViewController) -> Void)?
}

extension WKNavigationActionPolicy {
static let preventDeeplinkActionPolicy = WKNavigationActionPolicy(rawValue: WKNavigationActionPolicy.allow.rawValue + 2)!
}

0 comments on commit 84a170f

Please sign in to comment.