Member-only story

iOS: Why canOpenURL return false but app with url scheme is Present?

This app is not allowed to query for scheme <app>

Prafulla Singh
1 min readApr 20, 2020

canOpenUrl fails because Apple does not want application developers to query all installed app as this will be a privacy breach. Also, canOpenURL always works with apple preinstalled app.

There are two ways to fix this issue when dealing with third-party apps.

  1. Skip canOpenURL check and directly call open(_ url: URL, options: [UIApplication.OpenExternalURLOptionsKey : Any] = [:], completionHandler completion: ((Bool) -> Void)? = nil).
  2. Whitelist the app you want to redirect using LSApplicationQueriesSchemes.

Directly call open, we can skip open URL check and on call back we can define if user has app or user had declined to launch App.

Use Case: Browser or Web view redirection where App cannot know what app deep link may trigger

guard let whatsappsUrl = URL(string: "whatsapp://open") else {
return
}

UIApplication.shared.open(whatsapp, completionHandler: { (success) in
if
(success) {
print("whatsapp opened: \(success)")
} else { print("either WhatsApp not installed or user denied WhatsApp launch request")
}
})

Using LSApplicationQueriesSchemes, We can put all the possible apps schema, we want to open in info.plist and Open URL will work for all these schema.

Use Case: creating custom share dialogue etc

<dict>
...
<key>LSApplicationQueriesSchemes</key>
<array>
<string>whatsapp</string>
</array>
</dict>

--

--

Prafulla Singh
Prafulla Singh

Responses (2)