自定义URL方案,无需将应用程序放在前面

时间:2016-06-10 14:04:34

标签: objective-c macos cocoa url-scheme

我正在AppDelegate.m中处理这样的自定义网址方案:

-(void)applicationWillFinishLaunching:(NSNotification *)aNotification
{
    NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];
    [appleEventManager setEventHandler:self
                           andSelector:@selector(handleGetURLEvent:withReplyEvent:)
                         forEventClass:kInternetEventClass andEventID:kAEGetURL];
}

- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
{
    NSString * URL = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
    //Do my work with URL
}

它有效,但每次调用自定义方案时都不能将应用程序放在前面吗?

1 个答案:

答案 0 :(得分:0)

不幸的是,如果没有您的应用程序到达前台,就无法处理URL。

根据您正在做的事情,您可以使用App Extension进行工作。但这基本上是您唯一的其他潜在解决方案。

相关问题