I’m attempting to open UPI apps from swift WKWebView.
I’ve tried it utilizing including openURL into different utility if its not http or https.
Right here is the technique I’m following.
AppDelegate class
import Basis
import UIKit
class AppDelegate: NSObject, UIApplicationDelegate {
func utility(_ app: UIApplication, open url: URL, choices: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
return true
}
}
Right here is the Webview navigation delegate perform
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
currentWebView = webView
guard let url = navigationAction.request.url else {
decisionHandler(.enable)
return
}
print("NavAction URL: (url)")
if navigationAction.targetFrame == nil {
// Open in the identical tab if the goal body is nil (new tab)
print("NavAction 1")
currentWebView?.load(navigationAction.request)
decisionHandler(.cancel)
return
}
else if let url = navigationAction.request.url,
!url.absoluteString.hasPrefix("http://"),
!url.absoluteString.hasPrefix("https://"),
UIApplication.shared.canOpenURL(url) {
// Have UIApplication deal with the url (sms:, tel:, mailto:, ...)
UIApplication.shared.open(url, choices: [:], completionHandler: nil)
// Cancel the request (dealt with by UIApplication).
decisionHandler(.cancel)
}
decisionHandler(.enable)
}
How can I open the UPI apps the way in which safari opens them with a dialog saying Open in “GPay”.