iOS Handling URL Schemes

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Syntax

  1. // canOpenURL method verifies if there is any app which can handle indicated URL scheme.

  2. // Swift

    UIApplication.sharedApplication().canOpenURL(_ aUrl: NSURL)

  3. // Objective-C

    [[UIApplication sharedApplication] canOpenURL:(NSURL *)aUrl];

  4. // openURL method tries to open a resource located by URL. YES/true if it was opened otherwise NO/false.

  5. // Swift

    UIApplication.sharedApplication().openURL(_ aUrl: NSURL)

  6. // Objective-C

    [[UIApplication sharedApplication] openURL:(NSURL *)aUrl];

Parameters

ParameterMeaning
aUrla NSURL instance which stores a built-in or custom scheme string

Remarks

In iOS9 and above your app must list any URL schemes it will want to query. This is done by adding LSApplicationQueriesSchemes to Info.plist


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

Examples of built-in URL schemes:

tel: tel://123456890 or tel:123456890

http: http://www.google.com

facetime: facetime://[email protected]

mailto: mailto://[email protected]

sms: sms://123456890 or sms:123456890

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

Maps:

  • Using 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 tel scheme (for example * or #). This is done because of security concerns to prevent users from unauthorized redirect of calls, so in this case Phone app won't be opened.



Got any iOS Question?