Objective c 在cocoa应用程序中使用url方案创建新文档
我在Mac cocoa应用程序中实现了一个自定义URL方案。这是可行的,但我有几个问题 1) 我应该在基于文档的应用程序中的何处放置此代码以处理URL事件?我在我的Objective c 在cocoa应用程序中使用url方案创建新文档,objective-c,macos,cocoa,url-scheme,Objective C,Macos,Cocoa,Url Scheme,我在Mac cocoa应用程序中实现了一个自定义URL方案。这是可行的,但我有几个问题 1) 我应该在基于文档的应用程序中的何处放置此代码以处理URL事件?我在我的-windowcontrolleridloadnib:中有它,但如果应用程序关闭,它就不起作用,因为文档尚未设置 NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager]; [appleEventManager setE
-windowcontrolleridloadnib:
中有它,但如果应用程序关闭,它就不起作用,因为文档尚未设置
NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];
[appleEventManager setEventHandler:self andSelector:@selector(handleGetURLEvent:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL];
2) 如何将解析后的数据从URL发送到新文档?我正在从我的-handleGetURLEvent:withReplyEvent:
方法创建新文档,如下所示
[[NSDocumentController sharedDocumentController] newDocument:nil];
1) 我应该在基于文档的应用程序中的何处放置此代码以处理URL事件
最有可能的是在应用程序中委托ApplicationIDFinishLaunching方法
2) 如何将解析后的数据从URL发送到新文档
- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event
withReplyEvent:(NSAppleEventDescriptor *)replyEvent {
NSString *urlString = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
NSLog(@"URL: %@", urlString);
NSString *httpString = [urlString substringFromIndex:7];
NSLog(@“HTTP URL: %@", httpString);
[self openNewDocumentAtURL:[NSURL URLWithString:httpString]];
}
- (void)openNewDocumentAtURL:(NSURL *)absoluteURL {
NSDocumentController *docController = [NSDocumentController sharedDocumentController];
[docController newDocument:nil];
[(ResponseDocument *)[docController currentDocument] updateURL:absoluteURL];
}