0

I find it weird that though canOpenURL(myURL) is false while open(myURL) perfectly redirected to the app I want. What am I doing wrong here?

override func viewDidAppear(_ animated: Bool) {
    let instagramUrl = URL(string: "instagram://app")!
    print(UIApplication.shared.canOpenURL(instagramUrl))    // false
    if UIApplication.shared.canOpenURL(instagramUrl) {
        UIApplication.shared.open(instagramUrl, options: [:], completionHandler: nil)
    } else {
        UIApplication.shared.open(URL(string: "http://instagram.com")!, options: [:], completionHandler: nil)    // Instagram successfully launched???
        // UIApplication.shared.open(instagramUrl, options: [:], completionHandler: nil)        // This works too
        print("Open failed.")    // Open failed.
    }
}

Console:

-canOpenURL: failed for URL: "instagram://app" - error: "This app is not allowed to query for scheme instagram"

[MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles

[MC] Reading from public effective user settings.

My Info.plist as below

enter image description here

Lambdalex
  • 481
  • 1
  • 5
  • 10
  • Possible duplicate of [how to open instagram app on button click](https://stackoverflow.com/questions/38803801/how-to-open-instagram-app-on-button-click) – Jack Jul 15 '18 at 13:35

1 Answers1

3

You have to include your URL scheme into LSApplicationQueriesSchemes, not the URL itself.

So, instead of all the items in your current LSApplicationQueriesSchemes, you just need one item with the value instagram and it will work.

Papershine
  • 4,995
  • 2
  • 24
  • 48
  • 1
    Thank you so much!!! You literally saved my night!!! I am using the scheme stuff for the first time so I was somewhat lost. Thank you! – Lambdalex Jul 15 '18 at 13:46