Using URL Schemes

A URL scheme lets you communicate with other apps through a protocol that you define. To communicate with an app that implements such a scheme, you must create an appropriately formatted URL and ask the system to open it. To implement support for a custom scheme, you must declare support for the scheme and handle incoming URLs that use the scheme.

The scheme name (or protocol) of a URL is the first part of a URL - e.g. schemename://. For web pages the scheme is usually http (or https). iPhone supports these URL schemes:

  • http, https, ftp    Web links* (Safari)
  • mailto    E-mail links (launches the Mail app)
  • tel    Telephone Numbers (launches the phone app)
  • sms    Text Messages (launches the SMS app)
  • Web links that point to http://maps.google.com are redirected to the Maps app.
  • Web links that point to http://www.youtube.com are redirected to the YouTube app.
  • iTunes store links (http://phobos.apple.com/etc..) are sent to the iTunes (or App store) app.

iPhone apps can also specify their own custom URL scheme (for example, myapp://doStuff). What might you use a custom URL scheme for:

  • To transfer data from lite to paid versions of your app
  • To allow other apps (or even web pages) to call your app (and send data to it)
  • To handle callbacks for custom authentication (such as OAuth) and third party API's

The handlers for these schemes are fixed and cannot be changed. If your URL type includes a scheme that is identical to one defined by Apple, the Apple-provided app is launched instead of your app. For information about the schemes supported by apple, see Apple URL Scheme Reference.

How to check programmatically if App is installed

It's not possible to open or check if an app is installed by application bundle or Apple id. But you can operate with URL Schemes. If the app has registered a custom URL scheme, you can check if this scheme was registered on a current device and open this application by it's scheme.

For example, Facebook app has  fb://  Custom URL Scheme. And here is an example how you can check if this scheme is registered on a current device.

using SA.iOS.UIKit;
...
bool result = ISN_UIApplication.CanOpenURL("fb://");

If the result is TRUE,  it means that application that supports this scheme is currently installed on a device. And you can query this application by a URL scheme.

Using URL Schemes to Communicate with Apps

When you want to send data to an app that implements a custom URL scheme, create an appropriately formatted URL and call the ISN_UIApplication.OpenURL method of the app object. The ISN_UIApplication.OpenURL method launches the app with the registered scheme and passes your URL to it. At that point, control passes to the new app.

The following code fragment illustrates how one app can ask the Facebook app to open a feed page.

using SA.iOS.UIKit;
...
ISN_UIApplication.OpenURL("fb://feed");

Note: There is no callback: full control passes to the app you query. And there is no way to find out what is happening or happened inside that app after a query is sent.

For example here is a known Facebook app supported schemes:

  • fb://profile – Open Facebook app to the user’s profile.
  • fb://friends – Open Facebook app to the friends list.
  • fb://notifications – Open Facebook app to the notifications list (NOTE: there appears to be a bug with this URL. The Notifications page opens. However, it’s not possible to navigate to anywhere else in the Facebook app)
  • fb://feed – Open Facebook app to the News Feed.
  • fb://events – Open Facebook app to the Events page.
  • fb://requests – Open Facebook app to the Requests list.
  • fb://notes – Open Facebook app to the Notes page.
  • fb://albums – Open Facebook app to Photo Albums list.

You can also find a lot more URL schemes supported by another app on the internet. We collected some of them in this article. You can also learn in a next article how to add URL scheme support by our app. 

Registering URL Schemes

 For each URL scheme, you want your app to use with the ISN_UIApplication.OpenURL or ISN_UIApplication.CanOpenURL method, you need to add scheme to the LSApplicationQueriesSchemes Array. Luckily, with the IOS Native Pro plugin you can do following 3 simple steps.

  1. Open an Editor Setting under: Stan's Assets -> IOS Native Pro -> Settings
  2. Choose UIKit module.
  3. Add as much scheme's as you need using a plus button.

Implementing Custom URL Schemes

If your app can receive specially formatted URLs, you should register the corresponding URL schemes with the system. Apps often use custom URL schemes to vend services to other apps. For example, the Maps app supports URLs for displaying specific map locations. Learn how to manage such behavior with IOS Native Pro in this article.