当我的应用程序启动时,我“很快”设置了一个 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?
回复我自己:
eventHandler必须在 applicationWillFinishLaunching: 中注册,而不是在 applicationDidFinishLaunching: 中注册
如果应用程序由于 URL 处理程序而启动,您仍然会收到 EvenHandler 回调,但前提是您在启动过程中很快注册了它。
| 归档时间: |
|
| 查看次数: |
333 次 |
| 最近记录: |