Skip to content
This repository was archived by the owner on Oct 10, 2025. It is now read-only.

Commit c0cc9cd

Browse files
authored
Merge pull request #24 from magiclabs/ariflo-sc-77240-ios-sdk-webview-link-open-external-browser
Open URL in Mobile Browser if `open_in_device_browser` Flag Is True
2 parents e00b89d + 0093c5f commit c0cc9cd

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

MagicSDK.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
Pod::Spec.new do |s|
55
s.name = 'MagicSDK'
6-
s.version = '8.0.1'
6+
s.version = '8.1.0'
77
s.summary = 'Magic IOS SDK'
88

99
s.description = <<-DESC

Sources/MagicSDK/Core/Relayer/WebViewController.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,26 @@ class WebViewController: UIViewController, WKUIDelegate, WKScriptMessageHandler,
224224
} catch {}
225225
}
226226

227+
/**
228+
* The WKWebView will call this method when a web application calls window.open() in JavaScript.
229+
*/
230+
func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? {
231+
// Make sure the URL is set.
232+
guard let url = navigationAction.request.url,
233+
let urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: true),
234+
let openInDeviceBrowser = urlComponents.queryItems?.first(where: { $0.name == "open_in_device_browser" })?.value?.lowercased()
235+
else {
236+
return nil
237+
}
238+
239+
if UIApplication.shared.canOpenURL(url) && openInDeviceBrowser == "true" {
240+
// Open the link in the external browser.
241+
UIApplication.shared.open(url, options: [:], completionHandler: nil)
242+
}
243+
244+
return nil
245+
}
246+
227247
// handle external link clicked events
228248
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
229249
// Check for links.

0 commit comments

Comments
 (0)