Manos Chorianopoulos

fix campaign webview deeplinks

...@@ -146,6 +146,35 @@ var timer2: DispatchSourceTimer? ...@@ -146,6 +146,35 @@ var timer2: DispatchSourceTimer?
146 } 146 }
147 }) 147 })
148 } 148 }
149 +
150 + public func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
151 +
152 +// if(navigationAction.navigationType == .linkActivated) {
153 +
154 + if let redirectedUrl = navigationAction.request.url {
155 + // Example Deeplink: https://cosmote.page.link/loyaltyWallet
156 + // Example Deeplink: https://preview.page.link/cosmote.page.link/loyaltyWallet
157 + // Example Deeplink: https://apps.apple.com/app/id482889196?mt=8
158 +
159 + if redirectedUrl.absoluteString.contains("cosmote.page.link") {
160 +
161 + // check if link can be opened.
162 + guard UIApplication.shared.canOpenURL(redirectedUrl) else {
163 + decisionHandler(.cancel)
164 + return
165 + }
166 +
167 + UIApplication.shared.open(redirectedUrl, options: [:], completionHandler: nil)
168 +
169 + decisionHandler(.cancel)
170 + return
171 + }
172 + }
173 +
174 +// }
175 +
176 + decisionHandler(.allow)
177 + }
149 178
150 // MARK: - WKScriptMessageHandler 179 // MARK: - WKScriptMessageHandler
151 public func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) { 180 public func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
......