Handling URL Schemes

suggest change

Syntax

canOpenURL reports whether an installed app can handle the URL scheme. These calls are Swift 2 and the older Objective-C names. Swift 3 uses UIApplication.shared. openURL is deprecated; iOS 10 opens URLs with open(_:options:completionHandler:).

UIApplication.sharedApplication().canOpenURL(aUrl)
[[UIApplication sharedApplication] canOpenURL:aUrl];

openURL tries to open the resource. It returns YES/true when the URL was opened, otherwise NO/false.

UIApplication.sharedApplication().openURL(aUrl)
[[UIApplication sharedApplication] openURL:aUrl];

Parameters

Parameter Meaning
aUrl An NSURL that stores a built-in or custom scheme string

Remarks

In iOS 9 and above, an app must list any URL schemes it wants to query. Add them to LSApplicationQueriesSchemes in Info.plist. canOpenURL returns false for a scheme that is not listed.


iOS has built-in support for the tel, http/https, sms, mailto, and facetime schemes. It also supports http-based URLs for YouTube, Maps, and iTunes.

Examples of built-in URL schemes:

tel: tel:123456890 (tel://123456890 is also seen, but the scheme is tel:)

http: http://www.google.com

facetime: facetime://azimov@demo.com

mailto: mailto:azimov@demo.com

sms: sms:123456890 or sms://123456890

YouTube: https://www.youtube.com/watch?v=-eCaif2QKfA

Maps:

iTunes: https://itunes.apple.com/us/artist/randy-newman/id200900

Note: Not all special characters are supported in the tel scheme (for example * or #). This is done because of security concerns, to prevent an unauthorized redirect of a call, and in that case the Phone app will not open.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents