Melissa Lim
Melissa Lim

Reputation: 55

Added scheme to LSApplicationQueriesSchemes but canOpenURL still fails

Please help! Why am i still getting not allowed to query for scheme despite including the scheme in the LSApplicationQueriesSchemes?

My class:

class LearningBotScreen: UIViewController {

    @IBAction func googleAssistantOpenButtonPressed(_ sender: Any) {
        let googleAssistantUrl = URL(string:"youtube://")!

        if UIApplication.shared.canOpenURL(googleAssistantUrl){
            print("opening");
            UIApplication.shared.open(googleAssistantUrl)
            /*UIApplication.shared.open(googleAssistantUrl!, options:[:], completionHandler: nil)*/
        }
        else{
            print("download app")
            UIApplication.shared.open(URL(string: "http://apps.apple.com/sg/app/id1220976145")!, options: [:], completionHandler: nil)
            }


}

My info.plist:

    <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0">
    <dict>
    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>instagram</string>
        <string>youtube</string>
    </array>
    <key>LSApplicationCategoryType</key>    <string></string>    
    <key>CFBundleExecutable</key>   <string>$(EXECUTABLE_NAME)</string>      
    <key>CFBundleIdentifier</key>   <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>    
    <key>CFBundleInfoDictionaryVersion</key>    <string>6.0</string>     
    <key>CFBundleName</key>     <string>$(PRODUCT_NAME)</string>     
    <key>CFBundlePackageType</key>  <string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>      
    <key>CFBundleShortVersionString</key>   <string>1.0</string>     
    <key>CFBundleVersion</key>  <string>1</string> </dict> </plist>

The error message

2019-12-17 15:58:08.426142+0800 drmorpheus[1000:203271] -canOpenURL: failed for URL: "youtube://" - error: "This app is not allowed to query for scheme youtube" download app

updated code

Upvotes: 4

Views: 3530

Answers (1)

TylerP
TylerP

Reputation: 9829

You've edited the info.plist that belongs to your UI tests target, not your app target. Add the LSApplicationQueriesSchemes entry to your app's info.plist instead.

Upvotes: 1

Related Questions