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
Macos 在Mac Catalyst应用程序中使用UIDocumentPickerViewController读取文件需要读/写权限?_Macos_Appstore Sandbox_Entitlements_Mac Catalyst - Fatal编程技术网

Macos 在Mac Catalyst应用程序中使用UIDocumentPickerViewController读取文件需要读/写权限?

Macos 在Mac Catalyst应用程序中使用UIDocumentPickerViewController读取文件需要读/写权限?,macos,appstore-sandbox,entitlements,mac-catalyst,Macos,Appstore Sandbox,Entitlements,Mac Catalyst,我在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(@“已取消”);
}
这允许用户在系统的任何位置选择文件,并将其内容导入应用程序。如果我将App Sandbox>User Selected File功能设置为读/写,它就可以工作。但我只是从文件中读取数据,我不需要更新文件或保存沙箱之外的任何内容。因此,我将功能更改为只读,但随后在控制台中出现此错误,并且未调用
didpickDocumentsThatals

未能为[path]创建FPSandboxingURLWrapper。错误:Error Domain=NSPOSIXErrorDomain Code=1“无法为“[path]”发出沙盒扩展com.apple.app-sandbox.read-write:不允许操作”


这似乎是正确的,还是我应该能够读取仅具有只读权限的文件?如果需要,可以很容易地将其切换为读/写,但我的第一次提交由于使用了不必要的权限而被拒绝,如果确实需要,我想准备向审查小组证明这一点。

我继续并将权限更改为读/写,并在App Sandbox信息字段中随附说明,说明如何使用文件访问。该应用程序已获得批准。

对于搜索此应用程序的任何人,我没有通过陈述我的案例获得应用程序批准,而是被迫找到以下解决方案,即使用UIDocumentBrowserViewController(只读!)而不是UIDocumentPickerViewController(需要读写)

<代码>导入基础 导入UIKit 扩展视图控制器:UIDocumentBrowserVIEWController远程门,UIDocumentPickerDelegate{ @objc func presentDocumentPicker(){ 如果操作系统==.macintosh{ 让documentPicker=UIDocumentBrowserViewController(用于打开:[.pdf]) documentPicker.delegate=self documentPicker.allowsDocumentCreation=false documentPicker.allowsPickingMultipleItems=false //演示文档选择器。 当前(documentPicker,动画:真,完成:无) }否则{ 让documentsPicker=UIDocumentPickerViewController(用于打开内容类型:[.pdf]) documentsPicker.delegate=self documentsPicker.allowsMultipleSelection=false documentsPicker.modalPresentationStyle=.fullScreen self.present(documentsPicker,动画:true,完成:nil) } } func documentBrowser(u控制器:UIDocumentBrowserViewController,didPickDocumentsAt documenturl:[URL]){ guard let url=documentURLs.first,url.startAccessingSecurityScopedResource()否则{return} 推迟{ DispatchQueue.main.async{ url.stopAccessingSecurityScopedResource()的 } } debugPrint(“[DocumentPicker]所选项目,URL:”,URL) 控制器。解除(动画:真) } public func documentPicker(u控制器:UIDocumentPickerViewController,didPickDocumentsAt URL:[URL]){ guard let url=url.first,url.startAccessingSecurityScopedResource()else{return} 推迟{ DispatchQueue.main.async{ url.stopAccessingSecurityScopedResource()的 } } debugPrint(“[DocumentPicker]所选项目,URL:”,URL) 控制器。解除(动画:真) } 取消公共函数文档选择器(u控制器:UIDocumentPickerViewController){ 控制器。解除(动画:真) } }