Ios UIDocumentPickerViewController未在Mac Catalyst上调用DidPickDocumentTurl
我在Ios UIDocumentPickerViewController未在Mac Catalyst上调用DidPickDocumentTurl,ios,objective-c,mac-catalyst,uidocumentpickerviewcontroller,Ios,Objective C,Mac Catalyst,Uidocumentpickerviewcontroller,我在UIViewController中有此代码,该代码确认为UIDocumentPickerDelegate: - (void)openTextFilePicker { NSArray *UTIs = [NSArray arrayWithObjects:@"public.text", nil]; [self openFilePicker:UTIs]; } - (void)openFilePicker:(NSArray *)UTIs { UIDocumentPickerV
UIViewController
中有此代码,该代码确认为UIDocumentPickerDelegate
:
- (void)openTextFilePicker {
NSArray *UTIs = [NSArray arrayWithObjects:@"public.text", nil];
[self openFilePicker:UTIs];
}
- (void)openFilePicker:(NSArray *)UTIs {
UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:UTIs inMode:UIDocumentPickerModeImport];
documentPicker.delegate = self;
documentPicker.popoverPresentationController.barButtonItem = self.importButton;
[self presentViewController:documentPicker animated:TRUE completion:nil];
}
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURLs:(NSArray<NSURL *> *)urls {
[self documentPicker:controller didPickDocumentAtURL:[urls firstObject]];
}
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url {
NSLog(@"picked document %@", url);
}
- (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller {
NSLog(@"cancelled");
}
-(void)openTextFilePicker{
NSArray*UTIs=[NSArray arrayWithObjects:@“public.text”,nil];
[自打开文件选择器:UTIs];
}
-(void)openFilePicker:(NSArray*)UTIs{
UIDocumentPickerViewController*documentPicker=[[UIDocumentPickerViewController alloc]initWithDocumentTypes:UTIs inMode:UIDocumentPickerModeImport];
documentPicker.delegate=self;
documentPicker.popoverPresentationController.barButtonItem=self.importButton;
[self-presentViewController:documentPicker动画:真实完成:无];
}
-(void)documentPicker:(UIDocumentPickerViewController*)控制器didPickDocumentTurls:(NSArray*)URL{
[self-documentPicker:controller-DidPickDocumentTurl:[URL-firstObject]];
}
-(void)documentPicker:(UIDocumentPickerViewController*)控制器DIDPickDocumentTurl:(NSURL*)url{
NSLog(@“挑选的文档%@”,url);
}
-(无效)文档选择器取消:(UIDocumentPickerViewController*)控制器{
NSLog(@“已取消”);
}
这在iOS中运行良好。在Mac Catalyst中,文件选择器打开,我可以导航并选择一个文件,但当我单击选择器中的打开按钮时,既不会调用didPickDocumentAtURL
也不会调用didPickDocumentAtURL
。但是,如果单击选取器中的取消按钮,将调用documentPickerWasCancelled
单击“打开”时,控制台中会出现以下错误:
无法将拾取的URL文件的缩略图:///****与
收件箱复制文件://**:错误域=QLThumbnailErrorDomain代码=102
“(null)”UserInfo={NSUnderlyingError=0x600000da9a10{Error
Domain=GSLibraryErrorDomain Code=7“没有文件存储:///**”
UserInfo={NSDescription=没有存储文件://**}
我想这可能意味着我的沙盒安全设置有问题,但当我将选择器模式更改为UIDocumentPickerModeOpen
时,该错误不再发生,但仍然没有调用didpickdocumentur
。无论如何,以下是我的沙盒设置:
我看过关于文档选择器打开空白的帖子,但这不是问题所在。我只看到过一篇文章似乎证实了它的有效性,但那是使用Swift。。。它能在Swift中工作但在目标C中被破坏吗?我还有什么别的东西没做吗
更新
下面是演示该问题的最少代码。与我的整个项目一样,这在iOS上运行良好,但不会在Mac上调用
didPickDocument…
委托方法。据我所知,您刚刚在方法签名中输入了错别字,正确的是
-(void)documentPicker:(UIDocumentPickerServiceController*)控制器
DidPickDocumentsThathls:(NSArray*)URL{
NSLog(@“拾取的URL%@”,URL);
//选择多个文档很酷,但需要iOS 11
[self-documentPicker:controller-DidPickDocumentTurl:[URL-firstObject]];
}
在iOS上工作正常,因为不推荐的旧版仍然支持
- (void)documentPicker:(UIDocumentPickerViewController *)controller
didPickDocumentAtURL:(NSURL *)url;
但macOS/Catalyst没有,所以您的委托由于缺少方法而没有被调用
已测试并可与Xcode 11.2兼容哦,天哪,你说得对!我在新方法名称中使用了复数“URL”,但没有使用“Document”。感谢您发现错误并确认解决方案。当这个选项可用时,我将奖励赏金。