I'm implementing a custom URL scheme for one of my apps and can't get it to work.
I added these lines to my Info.plist:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>MyApp URL</string>
<key>CFBundleURLSchemes</key>
<array>
<string>myscheme</string>
</array>
</dict>
</array>
In my application delegate I install the event handler in ApplicationDidFinishedLaunching:
NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];
[appleEventManager setEventHandler:self andSelector:@selector(handleGetURLEvent:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL];
but the method isn't called when I click on a link with the URL eg. "myscheme://test"
- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event
withReplyEvent:(NSAppleEventDescriptor *)replyEvent {
// Extract the URL from the Apple event and handle it here.
NSString* url = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
NSLog(@"%@", url);
}
What did I miss?
Info.plist
in your actual app bundle (not in Xcode) contain theCFBundleURLSchemes
key?Productname.app
bundle that you double-click in the Finder to launch your app. Does theInfo.plist
file inside the .app bundle contain your changes?