Mac : How to get custom URI parameters in application

905 Views Asked by At

I've registered a URI Scheme "testscheme" for my application. Also I've registered a URL handler in - (void)applicationDidFinishLaunching:(NSNotification *)aNotification through NSAppleEventManager

Below code to register the geturl handler

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

When I open "testscheme://some parameters" from browser for the first time(when my application is not running), OS opens my application.

If I check command line parameters I dont see "testscheme://some parameters" as command line arguments.

However, if I open the same url when my application is already running, I get URL in my GetURL handler registered with NSAppleEventManager.

I wanted to get the testscheme url parameters in my application either by command line or by GetURL handler when it's launched first time.

I also checked Mail.app, when i open mailto:[email protected] in browser the parameters properly passed to Mail.app. However, if I check the command line arguments at the same time using ps -ef for Mail.app, I don't see any parameters except the app path.

Please help me on this.

Thanks and Regards.

1

There are 1 best solutions below

0
On

I solved it by registering GetURL eventHandler in awakeFromNib instead of applicationDidFinishLaunching