[IOS] canOpenURL becomes false on iOS14

Verification environment

Xcode: 12.0.1 iOS: 14.0 Swift: 5

Event

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"

approach

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.

Implementation

Define the https scheme in LSApplicationQueriesSchemes as shown below. スクリーンショット_2020-09-28_17_33_02.png

When executed in this state, true is returned to canOpenURL safely. that's all.

Recommended Posts

[IOS] canOpenURL becomes false on iOS14
Arrangement of the problem that canOpenURL becomes false when changing the default browser / mailer on iOS14 and horizontal deployment survey results
ATDD development on iOS (basic)
Tracking Authorization Status memo on iOS 14
[Swift] Acquisition of IDFA on iOS14
Receive parameterized PUSH notifications on iOS
Using a local network on iOS 14