Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deep link into macOS app is not recognized

I'm trying to implement a deep link into an macOS application, but nothing seems to work.

So far, my AppDelegate.swift contains the following

func application(app: NSApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
    print("opened by link");
    return true
}

I also configured the info.plist with URLSchemes beeing my bundle identifier and URLIdentifier beeing simply zst

In a simple html-file I use the following code to test the deep link

<a href="zst://test/link">Test</a>

My app gets opened (or becomes active when already running), but the print statement is not executed.

What am I doing wrong here?

like image 794
ad_on_is Avatar asked Sep 17 '25 14:09

ad_on_is


1 Answers

Thanks to @Ssswift I found a solution. Used this code: How do you set your Cocoa application as the default web browser?

and converted it to swift with: https://objectivec2swift.com

works with Swift 3

in AppDelegate.swift added these lines

func applicationDidFinishLaunching(_ aNotification: Notification) {
    var em = NSAppleEventManager.shared()
    em.setEventHandler(self, andSelector: #selector(self.getUrl(_:withReplyEvent:)), forEventClass: AEEventClass(kInternetEventClass), andEventID: AEEventID(kAEGetURL))
}

func getUrl(_ event: NSAppleEventDescriptor, withReplyEvent replyEvent: NSAppleEventDescriptor) {
    // Get the URL
    var urlStr: String = event.paramDescriptor(forKeyword: keyDirectObject)!.stringValue!
    print(urlStr);

}
like image 144
ad_on_is Avatar answered Sep 20 '25 06:09

ad_on_is