Xamarin.iOS Universal Links

 

Universal Links are the preferred method of deep linking to your app in iOS 9+. Unlike Uri Scheme, there are a standard URL, with HTTP or HTTPS. This allows them to have a number of benefits over Uri Scheme including:

  1. Fallback to a website if the app is not installed
  2. Unique to you and no one else can use your URL.
  3. One URL that works for both your website and app. A seamless transition between the two.

Create or Update your App ID

In order to use Universal Links you need to enable Associated Domains in your AppID profile. You can tick it when creating your AppID or edit an existing AppID. Please note that if you edit, you may need to regenerate profiles based on that App Identifier. This is all done in the Apple Developer Portal.

Take note of your App ID Prefix (TeamID) for use later.

AppIDPrefix

Tick Associated Domains

AssociatedDomains

Create And Upload Your Association File

In order to use Universal Links you must have a corresponding website for your app and the ability to upload a file to it. If you don’t have a website then you can not use Universal Links. We need to create an association file that lets Apple verify that you are the owner of the domain.

Caveats

  1. You need a new association file for each domain and sub domain.
  2. Must be no greater than 128KB even when signed.

Create File

Create a new file called apple-app-site-association. There is no extension on this filename. In the

{
   "applinks": {
     "apps": [],
     "details": [
       {
         "appID": "9JA89QQLNQ.com.apple.wwdc",
         "paths": [ "/wwdc/news/", "/videos/wwdc/2015/*"]
       },
       {
         "appID": "ABCD1234.com.apple.wwdc",
         "paths": [ "*" ]
       }
     ]
   }
}

Replace the appID with your AppId, prefixed with your AppID prefix as I mentioned above.

Next you can add in the paths you want to associate. Enter in the path names, do not enter any domain names.

Upload File

Upload the file to the root of your website domain or create a new directory called .well-known and place the file in there. As a final note please do not add an extension to this file such as json or txt, it must have no extension.

Register In Your App

Now go to your Xamarin.iOS project and open up the Entltlements.plist file. If you don’t have one, create one

PListEditorFactory

Then in your Associated Domains add in the domain name you wish to associate.

Note: This must be prefixed with applinks: as shown below.

AssociatedDomains

 

iOS App Loaded

When an iOS app is loaded from a Universal Link, you can override the ContinueUserActivity in AppDelegate.cs to get the URL passed. From here you can them move around in your app as needed.

public override bool ContinueUserActivity(UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler)
{
     return base.ContinueUserActivity(application, userActivity, completionHandler);
}

If your app is not running, it will get called through a different method.

public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options)
{
    return base.OpenUrl(app, url, options);
}

If you want more specific details on how to configure Universal Links, check out Apple’s Support Universal Links documentation.


XAMARIN.FORMS MONTHLY NEWSLETTER

JOIN 1,000+ SUBSCRIBERS

  1. Don't miss out on updates
  2. The latest info from this site, Xamarin and the community
  3. Unsubscribe at any time*

* We use MailChimp, with double opt-in, and instant unsubscribe

Microsoft MVP | Xamarin MVP | Xamarin Certified Developer | Exrin MVVM Framework | Xamarin Forms Developer | Melbourne, Australia

Related Posts

5 Comments

    1. Adam Pedley

      Hi Ali. I have just updated the article to show you how that is done. When the app is not running in the background, you need to use the OpenUrl method which is shown above.

  1. Sergio

    Hi, Adam.
    Great post, like everything else I’ve been reading.

    Right now I’m implementing Deep Linking in a couple of applications with Xamarin. Forms, and I have a question. I have followed this specific post, and I have already managed to get one of the applications to open the other, but I need to go further and it is not clear to me.

    Once the execution passes through the code of each of the platforms:

    -ANDROID-
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
    protected override void OnCreate(Bundle bundle)
    {
    TabLayoutResource = Resource.Layout.Tabbar;
    ToolbarResource = Resource.Layout.Toolbar;

    base.OnCreate(bundle);

    var data = Intent?.Data?.EncodedAuthority;

    global::Xamarin.Forms.Forms.Init(this, bundle);

    LoadApplication(new App());
    }
    }

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

    }

    What do I have to do from there to open a specific page of the application?

    In Android I’m doing something like this:

    protected override void OnCreate(Bundle bundle)
    {
    TabLayoutResource = Resource.Layout.Tabbar;
    ToolbarResource = Resource.Layout.Toolbar;

    base.OnCreate(bundle);

    var param1 = Intent?.Data?.EncodedAuthority;
    var param2 = Intent?.Data?.LastPathSegment;

    global::Xamarin.Forms.Forms.Init(this, bundle);

    var app = new App(param1, param2);

    LoadApplication(app);
    }

    And then I pass the parameter to MainPage, which manages navigation to the page I want to reach, but I’m not sure it’s the right thing. I have not yet found a viable solution in iOS… What do you think?

    Thanks!

Leave A Comment?