Question

My Mac App needs to open and go to a specific page when its Custom URL Schemes clicked in the browser. To accomplish this, I added an NSAppleEventManager on applicationDidFinishLaunching

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{

NSAppleEventManager *eventManager = [NSAppleEventManager sharedAppleEventManager];
[eventManager setEventHandler:self
                  andSelector:@selector(handleGetURLEvent:withReplyEvent:)
                forEventClass:kInternetEventClass
                   andEventID:kAEGetURL];

}

This Event Manager Calls the following selector also in the AppDelegate:

- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
{
    NSString *urlString = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
    NSLog(urlString);
    //Parse & Do other stuff...
}

This works perfectly at getting the URL that called the App as long as the App is already running. The problem is if the App isn't running than the App will launch, but the URL that launched it never gets passed to handleGetURLEvent.

I'm sure this has something to do with applicationDidFinishLaunching being called after the URL Event has already happened. Is the URL event in the NSNotification or something?

I know this should be easy, but I have no idea what to do.

Thanks to anyone who is able to help.

Was it helpful?

Solution

Try putting the setEventHandler into awakeFromNib of your delegate

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top