Handling URL Schemes
suggest changeSyntax
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:
- Using an address:
http://maps.apple.com/?address=1,Infinite+Loop,Cupertino,California - Using coordinates:
http://maps.apple.com/?ll=46.683155557,6.683155557
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.