ios - iOS 13 如何将 UIDocumentPickerViewController 与 App Group 一起使用?
问题描述
我已经在我的应用程序中实现了一个 AppGroup,以准备与另一个应用程序共享数据。我已成功将文件从默认应用程序文档目录移动到该应用程序组。
FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.com.xxx.mydata")! as NSURL
现在我想使用 UIDocumentPickerViewController 从该容器中的文件中进行选择。在 iOS 13 中,我应该能够设置文档选择器从哪个目录开始。我的 documentPicker 如下所示:
@IBAction func fileAction(_ sender: UIButton)
{
// open a document picker, select a file
let importFileMenu = UIDocumentPickerViewController(documentTypes: ["public.data"],
in: UIDocumentPickerMode.import)
importFileMenu.delegate = self
if #available(iOS 13.0, *) {
print("File iOS 13+")
importFileMenu.directoryURL = FileManager.default.containerURL(
forSecurityApplicationGroupIdentifier: "group.com.xxx.mydata")!
} else {
// Fallback on earlier versions
print("File iOS <=12")
}
importFileMenu.modalPresentationStyle = .formSheet
self.present(importFileMenu, animated: true, completion: nil)
}
当我运行该应用程序时,它的行为与 iOS13 之前一样,在默认的应用程序文档目录中打开,并且应用程序组未显示为可供选择的可能性。打印语句显示“文件 iOS 13+”。
我是否缺少从该容器读取的权限,或者还有其他我错过的东西?谢谢!
解决方案
不,对不起,这不可能。Apple 表示从 AppGroup 中选择不是 UIDocumentPickerViewController 应该做的。我为此花费了我的“Apple Developer Tech Support”用途之一,这就是他们的答案。我暂时放弃了,转向了不同的方向。您应该能够在 AppGroup 中构建自己的文件列表并选择它们,而不是使用 UIDocumentPickerViewController。
推荐阅读
- asp.net - 在 Azure DevOps 中使用 MSBuild 在解决方案中构建特定项目
- pimcore - Pimcore 考试路由
- flutter - 从 Builder 在 Flutter 中制作唯一的 List Tile 项目
- javascript - 在 React 音频标签不起作用,而是只显示链接
- reactjs - StateManagement 工具与原生 useState
- flutter - Flutter webview:ssl_client_socket_impl 和 Uncaught SecurityError 错误
- sql-server - 如何在 Azure 数据仓库(突触)中授予架构级别权限?
- c# - 卸载几个参考后出现未知错误
- python - 如何在python中将数据框的列名从字符串转换为元组?
- python - 如何在数组中查找非字符串索引