0

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?

Season
  • 1,178
  • 2
  • 22
  • 42

1 Answers1

0

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.

Frankenstein
  • 15,732
  • 4
  • 22
  • 47
  • I have tried UIApplication.canOpenURL(), however, the link " https://qr.payme.hsbc.com" is starting with "https://", that means canOpenURL() is always true as there is a Safari browser can open it. – Season May 27 '20 at 07:14
  • You need to get the schema as I've mentioned. Not web URL. – Frankenstein May 27 '20 at 07:19
  • 1
    thanks for guiding me, and it seems following code has to be added into info.plist for canOpenURL to work. LSApplicationQueriesSchemes some_cheme – Season May 27 '20 at 07:31
  • @Season Oh, I totally forgot to mentioned that, Thanks for reminding. I'll update my answer. – Frankenstein May 27 '20 at 07:37