【发布时间】:2013-12-16 23:46:01
【问题描述】:
当我的 Mac 应用程序在浏览器中单击自定义 URL 方案时,它需要打开并转到特定页面。为此,我在 applicationDidFinishLaunching 上添加了一个 NSAppleEventManager
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSAppleEventManager *eventManager = [NSAppleEventManager sharedAppleEventManager];
[eventManager setEventHandler:self
andSelector:@selector(handleGetURLEvent:withReplyEvent:)
forEventClass:kInternetEventClass
andEventID:kAEGetURL];
}
此事件管理器还在 AppDelegate 中调用以下选择器:
- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
{
NSString *urlString = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
NSLog(urlString);
//Parse & Do other stuff...
}
只要应用程序已经在运行,这在获取调用应用程序的 URL 时非常有效。问题是,如果应用程序没有运行,那么应用程序将启动,但启动它的 URL 永远不会传递给 handleGetURLEvent。
我确定这与在 URL 事件发生后调用 applicationDidFinishLaunching 有关。是 NSNotification 中的 URL 事件还是什么?
我知道这应该很容易,但我不知道该怎么做。
感谢任何能够提供帮助的人。
【问题讨论】:
标签: macos cocoa url-scheme