Search code examples
swiftios9uiapplicationcustom-urlxcode7.2

This app is not allowed to query for scheme XYZ://


You might think it's a duplicate question, but it's not, I'm totally aware of all the answers on SO about the canOpenURL and its caveats on iOS 9, but here is my problem:

I'm trying to check if an specific app is installed on my device (both developed by me). I have declared the scheme on AppA as:

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLName</key>
        <string>com.my.company.id</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>XYZ</string>
        </array>
    </dict>
</array>

and on the other app, AppB I have added in info.plist:

<key>LSApplicationQueriesSchemes</key>
<array>
 <string>XYZ</string>
</array> 

Now, in AppB I'm trying to find out if I have AppA installed like this:

     internal static let appAScheme = "XYZ://"

 static func  AppAInstalled() -> Bool {

    let appAURL = NSURL(string: appAScheme)

    return UIApplication.sharedApplication().canOpenURL(appAURL!)


}

It always returns

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

How ever, If I try to open AppA from AppB it'll work with no problem!

// Works alright
UIApplication.sharedApplication().openURL(appAURL!)

I can't figure it out why!


Solution

  • I have found the solution to my own question. I'm answering it here instead of just deleting my question because it might help somebody someday.

    The problem here was that I'm trying to develop a framework for other developers, I have a test app that I'm using to check if everything is fine with my framework. I was setting LSApplicationQueriesSchemes values inside the framework target, not the actual test app. SO:

    You need to set the whitelist values in your app target's info.plist