How can I know if external app will be open or not when a link is loaded in WKWebView?

1k Views Asked by At

I have a WKWebView, the webview will load a link like https://qr.payme.hsbc.com/2/XXXXYYYZZZ.

And there two possible results when the link is loaded,
case 1 is an app called Payme will be opened when user has installed Payme app;
case 2 is webview will be redirected to a static page https://payme.hsbc.com/ when user has not installed Payme app.

My question is how can I know if the Payme app is opened?

1

There are 1 best solutions below

4
On BEST ANSWER

You could use deep linking or the apple recommended universal linking to check if an app is installed in a device. With deep linking what you need to do is to acquire a schema of the app that the app has already added. And you could check if the schema can be opened just like you would do for any other type of URLs. Here is an example:

let appSchemeString = "com.myAppScheme://"
let url = URL(string: appSchemeString)!
if UIApplication.shared.canOpenURL(url) {
    print("App is present")
} else {
    print("App is not")
}

You need to update your info.plist file to include the schemes you'll be opening in the application. You should append this:

<key>LSApplicationQueriesSchemes</key> 
<array>
<string>com.myAppScheme</string> 
</array>

Here is an entire youtube video link regarding this. Also, checkout universal-linking.