I've set a URL handler "soon" when my app is launching: in -(void)applicationDidFinishLaunching:(NSNotification*) :
[[NSAppleEventManager sharedAppleEventManager] setEventHandler:self andSelector:@selector(getUrl:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL];
LSSetDefaultHandlerForURLScheme((CFStringRef)@"myScheme", (__bridge CFStringRef)[[NSBundle mainBundle] bundleIdentifier]);
It works as expected, the getUrl:withReplyEvent: is called whenever an URL with myScheme:// scheme is opened!
But if my app is not running (quit), if in Safari I open an URL such as myScheme://some_valuable_info?action=doSomething, it launched my app... but how do i know I've been launched by a URL handler? How can I get the URL that trigger my application launch?
Responding to myself:
The eventHandler must be registered in the applicationWillFinishLaunching: , not in applicationDidFinishLaunching:
If the app is launched due to an URL handler, you'll still get the evenHandler callback, but only if you registered it very soon in the launching process.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With