获取用于启动OS X应用程序的初始URL

时间:2015-12-14 05:27:14

标签: swift macos url-scheme

我有一个用Swift编写的Mac应用程序,带有自定义URL方案。

如果应用程序正在运行并从链接打开,则一切正常。但是如果应用程序没有运行,则应用程序无法打开正确的页面。

我正在注册这样的通知:

let eventManager = NSAppleEventManager.sharedAppleEventManager()
eventManager.setEventHandler(self, andSelector: "handleGetURLEvent:replyEvent:", forEventClass: AEEventClass(kInternetEventClass), andEventID: AEEventID(kAEGetURL))

如何从首次发布中获取网址:

func applicationDidFinishLaunching(aNotification: NSNotification)

编辑1: 在我的app委托中,我有:

func handleGetURLEvent(event: NSAppleEventDescriptor?, replyEvent: NSAppleEventDescriptor?)

此功能被调用,在应用程序已打开时有效,但在应用程序关闭时无效。

2 个答案:

答案 0 :(得分:1)

我有完全相同的问题并通过将注册调用移动到

来解决它
applicationWillFinishLaunching(_ notification: Notification) 

答案 1 :(得分:0)

你几乎就在那里!

Looking at a tutorial article you might be looking at at,您仍然需要实施一种方法来处理" ["id"] => array(5) { [0] => int(10) [1] => int(11) [2] => int(12) [3] => int(14) [4] => int(13) } " Apple Event。

在Application Delegate中,创建一个如下所示的方法:

kAEGetURL
相关问题