Custom URL Types on Mac Objective-C

2019-08-05 09:29发布

问题:

How can I create custom URL types that I can perform an action with the data passed into the app. I've tried this with no luck:

- (void)handleURLEvent:(NSAppleEventDescriptor*)event withReplyEvent:(NSAppleEventDescriptor*)replyEvent

回答1:

You have to specify one or more keys for the CFBundleURLTypes dictionary in your app's property list file (or in XCode target editor).

Then in your app delegate applicationWillFinishLaunching write something like

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


回答2:

  1. Select your project in the left pane.
  2. Select your target in the list.
  3. Go to the Info tab.
  4. Add new URLs under URL Types.