Search code examples
swifturluikitios14

Can't open a link when the default browser has been changed


After updating to iOS 14 I cannot open urls in the browser if it has been changed from default Safari to Chrome.

I did some investigation and found that UIApplication.shared.canOpenURL(url) always returns false.

Please help.


Solution

  • For iOS 14+

    I suggest to add this to your Info.plist

     <key>LSApplicationQueriesSchemes</key>
        <array>
          <string>https</string>
        </array>
    

    By adding this you can continue to use method canOpenURL(_ url: URL) -> Bool

    guard let url = URL(string: "https://example.com") else { return }
    if UIApplication.shared.canOpenURL(url) {
        UIApplication.shared.open(url)
    }