简体   繁体   English

iOS 13 如何将UIDocumentPickerViewController 与App Group 一起使用?

[英]iOS 13 How to use UIDocumentPickerViewController with App Group?

I have implemented an AppGroup in my app in preparation for sharing data with another app.我已经在我的应用程序中实现了一个 AppGroup,以准备与另一个应用程序共享数据。 I have successfully moved files to that App Group from the default app documents directory.我已成功将文件从默认应用程序文档目录移动到该应用程序组。

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

Now I would like to select from the files in that container, using UIDocumentPickerViewController.现在我想使用 UIDocumentPickerViewController 从该容器中的文件中获取 select。 In iOS 13,I should be able to set which directory the document picker starts in. My documentPicker looks like this:在 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)
}

When I run the app, it acts as it did before iOS13, opening in the default app documents directory, and the App Group is not shown as a possibility for selection.当我运行该应用程序时,它的行为与 iOS13 之前一样,在默认的应用程序文档目录中打开,并且应用程序组未显示为可供选择的可能性。 The print statement shows "File iOS 13+".打印语句显示“文件 iOS 13+”。

Am I missing permissions to read from that container, or is there something else that I've missed?我是否缺少从该容器读取的权限,或者还有其他我错过的东西? Thanks!谢谢!

No, sorry, it can't be done.不,对不起,这不可能。 Apple says that selecting from an AppGroup is not what UIDocumentPickerViewController is supposed to do. Apple 表示从 AppGroup 中选择不是 UIDocumentPickerViewController 应该做的。 I spent one of my "Apple Developer Tech Support" uses on this, and that was their answer.我为此花费了我的“Apple Developer Tech Support”用途之一,这就是他们的答案。 I gave up on that for now, and went a different direction.我暂时放弃了,转向了不同的方向。 You should be able to build your own list of files in the AppGroup and select them, just not by using UIDocumentPickerViewController.应该能够在 AppGroup 和 select 中构建自己的文件列表,而不是使用 UIDocumentPickerViewController。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 UIDocumentPickerViewController 与 UINavigationController 一起使用? - How to use UIDocumentPickerViewController with UINavigationController? 让 UIDocumentPickerViewController 只允许在 iOS 13 上选择二进制数据文件 - Getting UIDocumentPickerViewController to only allow the selection of binary data files on iOS 13 如何在 iOS 13 中使用 UINavigationBarAppearance - How to use UINavigationBarAppearance in iOS 13 如何使用UIDocumentPickerViewController选择自定义类型? - How to use UIDocumentPickerViewController to pick a custom type? iOS13 UIDocumentPickerViewController - 打开目录不显示选择/打开/取消按钮 - iOS13 UIDocumentPickerViewController - open directory does not display select/open/cancel buttons 如何在 Swift 5 和 iOS 13 中使用 CIFilter sunbeamsGenerator? - How to use CIFilter sunbeamsGenerator in Swift 5 and iOS 13? 如何在 iOS 13 或更高版本中使用 Sinch VOIP? - How to use Sinch VOIP with iOS 13 or higher? 如何在模拟器 iOS 13 中使用黑暗模式? - How to use dark mode in simulator iOS 13? 如何将 iOS 13 暗模式用于 wkwebview - how to use iOS 13 darkmode for wkwebview 如何使用 ios 13 的新 insertTextPlaceholder? - How to use new insertTextPlaceholder of ios 13?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM