iOS 13如何通过App Group使用UIDocumentPickerViewController?

问题描述 投票:1回答:1

我已经在我的应用程序中实现了一个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 +”。

我是否缺少读取该容器的权限,或者还有其他遗漏的内容?谢谢!

ios swift ios-app-group uidocumentpickervc
1个回答
0
投票

[不,对不起,无法完成。苹果表示,从AppGroup中进行选择并不是UIDocumentPickerViewController应该做的。我为此花了我的“ Apple开发者技术支持”之一,这就是他们的答案。我暂时放弃了,转向了另一个方向。您应该能够在AppGroup中构建自己的文件列表并选择它们,而不能使用UIDocumentPickerViewController。

© www.soinside.com 2019 - 2024. All rights reserved.