-canOpenURL: failed for URL: “deep-link” — error: “This app is not allowed to query for scheme ”
When developing mobile applications, there are times that we like to open another app natively. In iOS world, we use “deeplink” to open an app programmatically. However, before you open the other app, you may want to check if the user’s device has installed the desired app already.
Below is the snippet opening the app using deeplink
guard let url = URL(string: deeplink) else { return }
UIApplication.shared.openURL(url)
Similarly, you make use of UIApplication.shared‘s function to check the app’s existence
guard let url = URL(string: deeplink) else {
return
}
let bool = UIApplication.shared.canOpenURL(url)
This code complies fine in XCode, but it does not deliver the result you expected. XCode will show you this error log when you
2020–04–24 14:40:17.076999+0800 yourgreattestingapp[349:11543] -canOpenURL: failed for URL: “deep://link?token=123” — error: “This app is not allowed to query for scheme deep”
To solve this, you need to specify the deeplink’s custom URL scheme in info.plist in order to make the os allow your app to do such query.
<key>LSApplicationQueriesSchemes</key>
<array>
<string>deep</string>
</array>
Thats it. 🙂
Happy coding.
Find me at Twitter @rick3817
Reference: