当我的应用程序启动时,我“很快”设置了一个 URL 处理程序:在 -(void)applicationDidFinishLaunching:(NSNotification*) 中:
[[NSAppleEventManager sharedAppleEventManager] setEventHandler:self andSelector:@selector(getUrl:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL];
LSSetDefaultHandlerForURLScheme((CFStringRef)@"myScheme", (__bridge CFStringRef)[[NSBundle mainBundle] bundleIdentifier]);
Run Code Online (Sandbox Code Playgroud)
它按预期工作,每当打开带有 myScheme:// 方案的 URL 时都会调用 getUrl:withReplyEvent: !
但是,如果我的应用程序没有运行(退出),如果在 Safari 中我打开一个 URL(例如 myScheme://some_valuable_info?action=doSomething),它会启动我的应用程序...但我如何知道我已通过 URL启动处理程序?如何获取触发应用程序启动的 URL?