Xcode: 12.0.1 iOS: 14.0 Swift: 5
When I tried to start the browser externally with the code below, the canOpenURL method became false and it was not started externally.
guard let url: URL = URL(string: "https://www.yahoo.co.jp/") else { return }
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
When I looked at the console, I got the following error message. The https URL scheme is not allowed.
-canOpenURL: failed for URL: "https://www.yahoo.co.jp/" - error: "This app is not allowed to query for scheme https"
As stated in the error message, https is not allowed, so you can allow it.
If you check Official documentation for canOpenUrl, add LSApplicationQueriesSchemes to info.plist and define the schemes to allow there. It looks good if you give it. (Quoted below)
If your app is linked on or after iOS 9.0, you must declare the URL schemes you pass to this method by adding the LSApplicationQueriesSchemes key to your app's Info.plist file. This method always returns false for undeclared schemes, whether or not an appropriate app is installed. To learn more about the key, see LSApplicationQueriesSchemes.
The app is also available in LSApplicationQueriesSchemes Documentation It says to specify a URL scheme that can be tested using the canOpenURL: method.
Define the https scheme in LSApplicationQueriesSchemes as shown below.
When executed in this state, true is returned to canOpenURL safely. that's all.
Recommended Posts