Re: handleGetURLEvent getting called after applicationDidFinishLaunching
Re: handleGetURLEvent getting called after applicationDidFinishLaunching
- Subject: Re: handleGetURLEvent getting called after applicationDidFinishLaunching
- From: Ken Thomases <email@hidden>
- Date: Tue, 20 Aug 2013 14:37:36 -0500
On Aug 20, 2013, at 1:38 PM, Bradley O'Hearne wrote:
> I have a Mac app that is launched via a URL handler that is installed. The launch services / configuration setup of the URL handler is fine, app launches just as expected. However, I am seeing an intermittent problem where the URL handling method:
>
> - (void)handleGetURLEvent:(NSAppleEventDescriptor *)event
> withReplyEvent:(NSAppleEventDescriptor *)replyEvent;
>
> is invoked after the app delegate method:
>
> - (void)applicationDidFinishLaunching:(NSNotification *)aNotification;
>
> Normally, handleGetURLEvent is invoked first, which is important, because the implementation of that method is usually needing to capture the URL used to launch it, for later processing. That is exactly my case, and when the applicationDidFinishLaunching method is invoked first, the app fails, because it doesn't have the launch URL which has information needed to run the app.
>
> So far, this problem seems isolated to Snow Leopard, I have not seen it on Lion or Mountain Lion. Also, the problem is intermittent -- it works just fine most of the time, even on the same machine where the problem occasionally occurs. My questions:
>
> 1. Is there any guaranteed invocation order of these methods, or is it completely random? I cannot think of any scenario where you'd want to process the URL launching event *after* the callback which signifies app launch completion. That just seems wrong.
No, you're mistaken. This is not a callback specifically for an app being launched to handle a URL. It's a callback to handle a request to open a URL, whenever it happens. It is perfectly normal for it to be delivered after an app is launched. Click a mailto: link on a website? Your mail program is told to handle it. It may be launched to handle it, but it's quite likely to have already been running. Click an http: link in an email? Your browser is told to handle it. Again, it may be launched if it's not already running, but it's quite likely to be already running.
Ideally, your code would just be able to handle the URL at the time the event is delivered to your handler, regardless of whether -applicationDidFinishLaunching: has already been invoked. -applicationDidFinishLaunching: is not all that special that you'd have to wait for it, at least from the framework's point of view. Nor should it be a problem to handle a URL after the app has launched.
If you for some reason really need to wait until both things have happened, then you can make both methods store information and then do the work in the last of them to occur. (Although there's no such thing as the "last" time your GetURL handler will be called. It can be called at arbitrary times and/or an arbitrary number of times during your app's lifetime.)
Regards,
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden