我有一个用Swift编写的带有自定义URL方案的Mac应用程序。
如果应用程序正在运行,并从一个链接打开,一切都很好。但是如果应用程序没有运行,那么应用程序就不会打开正确的页面。
我正在注册这样的通知:
let eventManager = NSAppleEventManager.sharedAppleEventManager()
eventManager.setEventHandler(self, andSelector: "handleGetURLEvent:replyEvent:", forEventClass: AEEventClass(kInternetEventClass), andEventID: AEEventID(kAEGetURL))如何从以下位置的初始启动获取url:
func applicationDidFinishLaunching(aNotification: NSNotification)编辑1:在我的应用代理中,我有:
func handleGetURLEvent(event: NSAppleEventDescriptor?, replyEvent: NSAppleEventDescriptor?)此函数被调用,并在应用程序已打开时起作用,但在应用程序关闭时不起作用。
发布于 2017-08-28 19:57:04
我遇到了完全相同的问题,并通过将注册调用移动到
applicationWillFinishLaunching(_ notification: Notification) 发布于 2015-12-14 14:37:20
你就快到了!
你仍然需要实现一个处理"kAEGetURL“Looking at a tutorial article you might be looking at at事件的方法。
在Application Delegate中,创建如下所示的方法:
func handleGetURLEvent(event: NSAppleEventDescriptor?, replyEvent: NSAppleEventDescriptor?) {
if let aeEventDescriptor = event?.paramDescriptorForKeyword(AEKeyword(keyDirectObject)) {
if let urlStr = aeEventDescriptor.stringValue {
let url = NSURL(string: urlStr)
// do something with the URL
}
}
}https://stackoverflow.com/questions/34260324
复制相似问题