ZAD-Man
ZAD-Man

Reputation: 1406

MacOS Universal Links not running expected function in AppDelegate

I'm trying to implement Universal Links in a Swift MacOS app, and clicking the link does open the app, but it's supposed to run the application function in AppDelegate with this signature:

func application(_ application: NSApplication,
                   continue userActivity: NSUserActivity,
                   restorationHandler: @escaping ([NSUserActivityRestoring]) -> Void) -> Bool

according to the documentation, but it isn't running. I've verified this using os_log() - I've placed logs all around my app, including this function, and all are hit as expected except this one.

Here's the process of how I got to this point:

  1. Add the proper associations Associated Domains in Xcode, plus my AASA
  2. Run my app in Xcode
  3. Paste the universal link into Notes, then click it
  4. The first time, the link opened in Safari, then I selected that I wanted to open it in my app
  5. The app now opens every time I click the link

I need to have information from the link, so I really need to get the URL from userActivity, but so far clicking the Universal Link seems to behave as if just clicked the app.

Am I missing something? Am I incorrectly expecting it to work similarly to iOS Universal Links?

Upvotes: 0

Views: 611

Answers (1)

ZAD-Man
ZAD-Man

Reputation: 1406

It seems I have found the answer - in the docs (and even when you select "Jump to Definition" for NSApplicationDelegate), it says to use

restorationHandler: @escaping ([NSUserActivityRestoring]) -> Void

as your last parameter, but when you type "application" and select from the autocomplete, it comes up with

restorationHandler: @escaping ([Any]) -> Void

as the last parameter. With that in place instead, it was called when I clicked the Universal Link.

Upvotes: 1

Related Questions