Instance Method

canOpenURL(_:)

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

Declaration

func canOpenURL(_ url: URL) -> Bool

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

false 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, true.

Discussion

When this method returns true, iOS guarantees subsequent calls to the open(_: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 false. If the user reinstalls or upgrades the app, iOS resets the limit.

Unlike this method, the open(_: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

class let openSettingsURLString: String

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.