Registering A Uri Scheme

WinRT / UWP

Go to your package.appxmanifest and go to declarations. Add a new protocol and in the Name: section add in your uri scheme.


iOS

Open up your info.pList in an XML editor and add in the following key and values, replacing my-app with your Uri Scheme.

<key>CFBundleURLTypes<key>
<array>
  <dict>
    <key>CFBundleURLName</key>
    <string>myapp</string>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>my-app</string>
    </array>
  </dict>
</array>


Android

Open up your AndroidManifest.xml and add in an intent as below, replacing my-app with your Uri Scheme.

<application android:label="My App" android:icon="@drawable/icon">
  <activity android:icon="@drawable/icon" android:label="My App" android:name="mobile">
    <intent-filter>
      <action android:name="android.intent.action.VIEW" />
      <category android:name="android.intent.category.DEFAULT" />
      <category android:name="android.intent.category.BROWSABLE" />
      <data android:scheme="my-app" />
    </intent-filter>
  </activity>
</application>


Pass through parameters

Along with the Uri Scheme you can also pass through parameters or more information. Much like a traditional Uri which contains a domain name then some form of identifier and query string parameters, you can do much the same.


If you do pass through parameters like so, how do you get hold of them in the app?


twitter://compose?text=Hello


There is a place in each platform that allows you to retrieve the value.


WinRT / UWP

In your App.xaml.cs in your native WinRT / UWP app, override the following.

protected override void OnActivated(IActivatedEventArgs args)
{
     if (args.Kind == ActivationKind.Protocol)
     {
         ProtocolActivatedEventArgs eventArgs = args as ProtocolActivatedEventArgs;
         var url = eventArgs.Uri.AbsoluteUri;
     }
     base.OnActivated(args);
}


iOS

In your AppDelegate.cs you just need to override OpenUrl.

public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options)
{

}


Android

In the MainActivity.cs file, or the activity that will be loaded when the app starts, in your OnCreate, you can capture the data as shown below.

protected override void OnCreate(Bundle bundle)
{
    base.OnCreate(bundle);
    var data = Intent?.Data?.EncodedAuthority;
}


Problems with Uri Scheme

Uri Scheme is an older concept and is not actively promoted as the best way forward today. UWP unfortunately as no other way, however iOS has Universal Links and Android has App Links. While you are still free to use Uri Scheme there are some challenges you may face.


  1. You are not guaranteed the Uri Scheme you choose. Another app can be installed after yours and take over your Uri Scheme. Uri Schemes are registered on who was the last to take the name.
  2. iOS Apps can no longer tell if an app is installed via a Uri Scheme unless the Uri Scheme is listed in the info.pList.
  3. It doesn’t have a fallback if the app isn’t installed, whereas other options such as universal links have a website fallback if the app is not installed.