我已经在我的应用程序中实现了一个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之前一样,在默认的应用程序文档目录中打开,并且未显示“应用程序组”作为选择的可能性。打印语句显示“File iOS 13+”。
我是否缺少读取该容器的权限,或者还有其他遗漏的内容?
谢谢!
最佳答案
不,抱歉,无法完成。苹果表示,从AppGroup中进行选择不是UIDocumentPickerViewController应该执行的操作。我为此花了我的“Apple开发者技术支持”中的一种,这就是他们的答案。我暂时放弃了,转向了另一个方向。您应该可以让能够在AppGroup中构建您自己的文件列表并选择它们,而不能使用UIDocumentPickerViewController。
关于ios - iOS 13如何将UIDocumentPickerViewController与App Group一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58573163/