3

when I using canOpenURL to open universal link, (target app is installed)

canOpenURL return true, but app is not opening (LSApplicationQueriesSchemes are not registered)

but if I use open(_ url, options) app is opening

If I am responsible for not registering LSApplicationQueriesSchemes, how do I register Universal's links to LSApplicationQueriesSchemes? (https://www.aaa.com)

<key>LSApplicationQueriesSchemes</key>
<array>
<string>https://www.aaa.com</string>
</array>

like this?

PrepareFor
  • 2,448
  • 6
  • 22
  • 36

1 Answers1

2

If AAA is the app that you're trying to open, there is another way to launch it from inside your app. You will need to grab the CFBundleURLSchemes that the target app uses.
For AAA its "aaamobile" For AAA Auto Club its "aaamobileace"

You then need to add the url schemes into your plist:

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>aaamobile</string>
</array>

And then in your code you can check to see if the app is installed and launch the app or take user to website:

    guard let url = URL(string: "aaamobile://") else { return }
    if UIApplication.shared.canOpenURL(url) {
        UIApplication.shared.open(url, options: [:], completionHandler: nil)
    } else {
        UIApplication.shared.open(URL(string: "https://www.aaa.com")!, options: [:], completionHandler: nil)
    }
valosip
  • 3,167
  • 1
  • 14
  • 26
  • How can we find out the `CFBundleURLSchemes` that those apps use? – lavta3 Mar 25 '20 at 03:15
  • 1
    @lavta3 I have a jailbroken device that I can use for testing purposes, so its super simple to pull those values if they exist. If you do not have a JB device, you can still find the same info by downloading the .ipa file and extracting the contents. I don't want to link to any tutorials as they might change, but a simple google search should yield the proper result. – valosip Mar 25 '20 at 03:22