Thunder
Thunder

Reputation: 631

Capture URL from URL Scheme in Cocoa

I've added an URL scheme to my app and it opens up (or is brought back to front if already open) correctly when clicked on a link "my_scheme://item_to_add".

I found how to capture the link on iOS:

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url;

Anyone can point me to a similar method on a Mac, where I would be able to capture the link?

Upvotes: 0

Views: 340

Answers (1)

Thunder
Thunder

Reputation: 631

Ok, found out the answer myself again ;)

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

And the implement the selector method:

- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:       (NSAppleEventDescriptor *)replyEvent
{
    NSString* url = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
    NSLog(@"%@", url);
}

Upvotes: 1

Related Questions