Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 在cocoa应用程序中使用url方案创建新文档_Objective C_Macos_Cocoa_Url Scheme - Fatal编程技术网

Objective c 在cocoa应用程序中使用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

我在Mac cocoa应用程序中实现了一个自定义URL方案。这是可行的,但我有几个问题

1) 我应该在基于文档的应用程序中的何处放置此代码以处理URL事件?我在我的
-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];
}