Instance Method

canOpenURL:

Returns a Boolean value indicating whether an app is available to handle a URL scheme.

Declaration

- (BOOL)canOpenURL:(NSURL *)url;

Parameters

url

A URL (Universal Resource Locator). At runtime, the system determines if an installed app is registered to handle the URL's scheme. More than one app can be registered to handle a scheme.

The URL can have a common scheme such as http, https, tel, or facetime, or a custom scheme. For information about supported schemes, see Apple URL Scheme Reference.

Return Value

NO if no app installed on the device is registered to handle the URL’s scheme, or if you have not declared the URL’s scheme in your Info.plist file; otherwise, YES.

Discussion

When this method returns YES, iOS guarantees subsequent calls to the openURL:options:completionHandler: method with the same URL will successfully launch an app that can handle the URL. The return value does not indicate the validity of the URL, whether the specified resource exists, or, in the case of a universal link, whether an installed app is registered to respond to the universal link.

If your app is linked against an earlier version of iOS but is running in iOS 9.0 or later, you can call this method up to 50 times. After reaching that limit, subsequent calls always return NO. If the user reinstalls or upgrades the app, iOS resets the limit.

Unlike this method, the openURL:options:completionHandler: method is not constrained by the LSApplicationQueriesSchemes requirement. If an app is available to handle the URL, the system will launch it, whether or not you have declared the scheme.

Using universal links instead of custom URL schemes removes the need to use this method to validate target links; if no app is available to handle a universal link, iOS routes it to Safari, allowing the associated website to respond. For more information on universal links, see Allowing Apps and Websites to Link to Your Content.

See Also

Opening a URL Resource

- openURL:options:completionHandler:

Attempts to open the resource at the specified URL asynchronously.

UIApplicationOpenExternalURLOptionsKey

Options for opening a URL.

UIApplicationOpenSettingsURLString

Used to create a URL that you can pass to the openURL: method. When you open the URL built from this string, the system launches the Settings app and displays the app’s custom settings, if it has any.