【问题标题】:iOS 13 How to use UIDocumentPickerViewController with App Group?iOS 13 如何将 UIDocumentPickerViewController 与 App Group 一起使用?
【发布时间】:2019-10-26 17:34:44
【问题描述】:

我已经在我的应用中实现了一个 AppGroup,以准备与另一个应用共享数据。我已成功将文件从默认应用文档目录移至该应用组。

FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.com.xxx.mydata")! as NSURL

现在我想使用 UIDocumentPickerViewController 从该容器中的文件中进行选择。在 iOS 13 中,我应该能够设置文档选择器从哪个目录开始。我的文档选择器如下所示:

@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+”。

我是否缺少从该容器中读取的权限,或者我还缺少其他什么? 谢谢!

【问题讨论】:

  • 约翰,你有没有找到解决办法?我看到了同样的问题,我能找到的关于它的唯一帖子是你的,没有回复。 :(

标签: ios swift ios-app-group uidocumentpickervc


【解决方案1】:

不,抱歉,无法完成。 Apple 表示从 AppGroup 中选择不是 UIDocumentPickerViewController 应该做的。我为此花费了我的“Apple Developer Tech Support”用途之一,这就是他们的答案。我暂时放弃了它,并朝着不同的方向前进。您应该能够在 AppGroup 中构建您自己的文件列表并选择它们,而不是使用 UIDocumentPickerViewController。

【讨论】:

  • 感谢您的回复,我什至认为这不是我想听到的!
猜你喜欢
  • 1970-01-01
  • 2020-12-11
  • 2016-03-15
  • 1970-01-01
  • 2022-10-22
  • 1970-01-01
  • 1970-01-01
  • 2017-10-11
  • 2014-03-18
相关资源
最近更新 更多