iosmacosmacos-sierraios-universal-links

How to configure universal links to work from a web browser to a Mac app on macOS?


Since iOS9, universal links work on iOS, but I am wondering if there is something like that on macOS? We have an application that is a macOS-App with a corresponding Web-App, and we would love links clicked by the user to open in the Mac-App instead of opening the browser with the target-link.

Is that anyhow possible on macOS? I just found samples for iOS, but none for macOS?!?


Solution

  • Supporting Universal Links on macOS requires support from both your app and your website (and macOS 10.15+).

    See Apple's documentation Allowing Apps and Websites to Link to Your Content for details (the article deals with iOS, tvOS and macOS deep links), and its sub-articles Enabling Universal Links as well as Handling Universal Links.

    Quick overview:

    Basically, it's the same as on iOS: you need to create an apple-app-site-association file that is hosted on your server either in the root directory or in the .well-known directory (described in "Enabling Universal Links" linked above). It describes which URL paths can be passed to your app. It's important that this file is valid JSON (validate it!) and is served via HTTPS with a valid certificate and without any redirects!

    You need to enable the "Associated Domains" capability in your provisioning profile. Details depend on whether Xcode manages your profiles or not. In your entitlements file (usually editable via the "Signing & Capabilities" tab of your target in Xcode) you need add the corresponding associated domain, like applinks:my.domain.example (no https:// or anything, just the raw domain name).

    Then you need to implement application(_:continue:restorationHandler:) in your app delegate to handle the Universal Link.

    It can be annoying to make macOS pick up the association for the first time during development. Debugging hints:


    1) Sorry, don't have a dev forum link where I read this.

    2) Again, sorry, don't have a link right now. Saw this stated at least two times by Apple employees, both cited the Notes trick. Even though they were talking about iOS there, this behaviour is the same on macOS as well.