如何在 iPhone 的文件应用程序中显示我的应用程序文档

How can I display my App documents in the Files app for iPhone

我正在尝试在 iPhone 的“文件”应用程序中显示我的应用程序中的数据 查了很多都对了,不知道哪里出错了

func fileManger(nameFolder: String) {

    let manager = FileManager.default
    let DecomentFolder = manager.urls(for: .documentDirectory, in: .userDomainMask).last
    let Folder = DecomentFolder?.appendingPathComponent("\(nameFolder)")

    do {
        try manager.createDirectory(at: Folder!, withIntermediateDirectories: true, attributes: [:])
    } catch let error {
        print(error.localizedDescription)
    }
}

我也在这里发送值作为一个文件夹

@objc func alertNewFolder () {
    let alert = UIAlertController(title: "Create an album", message: "", preferredStyle: .alert)
    alert.addTextField(configurationHandler: nil)
    alert.textFields![0].placeholder = "name album"
    alert.textFields![0].textAlignment = .right
    alert.addAction(UIAlertAction(title: "cancel", style: .cancel, handler: nil))
    alert.addAction(UIAlertAction(title: "save", style: .default, handler: { ـ in
        if let textFileds = alert.textFields {
            let links = textFileds[0].text
            self.arrS1.append(addCatogrey(nameCatog: links!, imageSection: UIImage(named: "folder")))
// Here Send FileManager
            helperCoding().fileManger(nameFolder: links!)
            self.collection.reloadData()
        }
    }))
    self.present(alert, animated: true, completion: nil)
}

在模拟器中它正确地保存在此处的文档文件夹中

/Users/badrshammry/Library/Developer/CoreSimulator/Devices/7986A27F-7026-45E1-9073-78CCD6A9B90A/data/Containers/Data/Application/3173C4DC-BCDE-41B9-89E1-6E8D9B52EF25/Documents

如果您想在 Apple 的文件应用程序中公开您的应用程序文档文件,您需要在信息 plist 文件中包含 "Supports Document Browser" 键并将其设置为 YES:

要设置 Supports Document Browser,必须在 info 选项卡的 Custom iOS Target Properties 中设置

info.plist 不再来自 Xcode 13

总之,不行。文件应用程序不会在您的应用程序包中找到文件。它们需要“共享”(在 SwiftUI 中使用 UIViewControllerRepresentable

但是你的应用程序在文件结构中不会有文件应用程序可见的目录。添加那个文件夹仍然是个谜

参见:How can folders visible to FIles app be created by App programatically