Manos Chorianopoulos

fix campaign webview deeplinks

......@@ -147,6 +147,35 @@ var timer2: DispatchSourceTimer?
})
}
public func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
// if(navigationAction.navigationType == .linkActivated) {
if let redirectedUrl = navigationAction.request.url {
// Example Deeplink: https://cosmote.page.link/loyaltyWallet
// Example Deeplink: https://preview.page.link/cosmote.page.link/loyaltyWallet
// Example Deeplink: https://apps.apple.com/app/id482889196?mt=8
if redirectedUrl.absoluteString.contains("cosmote.page.link") {
// check if link can be opened.
guard UIApplication.shared.canOpenURL(redirectedUrl) else {
decisionHandler(.cancel)
return
}
UIApplication.shared.open(redirectedUrl, options: [:], completionHandler: nil)
decisionHandler(.cancel)
return
}
}
// }
decisionHandler(.allow)
}
// MARK: - WKScriptMessageHandler
public func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
......