我正在为我的一个应用程序实施自定义 URL 方案,但无法使其正常工作。
我将这些行添加到我的 Info.plist 中:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>MyApp URL</string>
<key>CFBundleURLSchemes</key>
<array>
<string>myscheme</string>
</array>
</dict>
</array>
在我的应用程序委托中,我在 ApplicationDidFinishedLaunching 中安装了事件处理程序:
NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];
[appleEventManager setEventHandler:self andSelector:@selector(handleGetURLEvent:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL];
但是当我单击带有 URL 的链接时,不会调用该方法,例如。“我的方案://测试”
- (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);
}
我错过了什么?