Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #24 from magiclabs/ariflo-sc-77240-ios-sdk-webview…
Browse files Browse the repository at this point in the history
…-link-open-external-browser

Open URL in Mobile Browser if `open_in_device_browser` Flag Is True
  • Loading branch information
Ariflo authored May 10, 2023
2 parents e00b89d + 0093c5f commit c0cc9cd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion MagicSDK.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
Pod::Spec.new do |s|
s.name = 'MagicSDK'
s.version = '8.0.1'
s.version = '8.1.0'
s.summary = 'Magic IOS SDK'

s.description = <<-DESC
Expand Down
20 changes: 20 additions & 0 deletions Sources/MagicSDK/Core/Relayer/WebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,26 @@ class WebViewController: UIViewController, WKUIDelegate, WKScriptMessageHandler,
} catch {}
}

/**
* The WKWebView will call this method when a web application calls window.open() in JavaScript.
*/
func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? {
// Make sure the URL is set.
guard let url = navigationAction.request.url,
let urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: true),
let openInDeviceBrowser = urlComponents.queryItems?.first(where: { $0.name == "open_in_device_browser" })?.value?.lowercased()
else {
return nil
}

if UIApplication.shared.canOpenURL(url) && openInDeviceBrowser == "true" {
// Open the link in the external browser.
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}

return nil
}

// handle external link clicked events
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
// Check for links.
Expand Down

0 comments on commit c0cc9cd

Please sign in to comment.