无法识别深入 link 的 macOS 应用程序

Deep link into macOS app is not recognized

我正在尝试将 link 深入实施到 macOS 应用程序中,但似乎没有任何效果。

到目前为止,我的 AppDelegate.swift 包含以下内容

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

我还配置了 info.plist,其中 URLSchemes 是我的包标识符,而 URLIdentifier 只是 zst

在一个简单的 html 文件中,我使用以下代码来测试深度 link

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

我的应用程序已打开(或在已经 运行 时激活),但未执行打印语句。

我做错了什么?

感谢@Ssswift 我找到了解决方案。 使用此代码: How do you set your Cocoa application as the default web browser?

并将其转换为 swift 并使用:https://objectivec2swift.com

适用于 Swift 3

AppDelegate.swift 中添加了这些行

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);

}