【问题标题】:How can I display my App documents in the Files app for iPhone如何在 iPhone 的文件应用程序中显示我的应用程序文档
【发布时间】:2022-01-06 20:54:53
【问题描述】:

我正在尝试在 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)
}

在模拟器中正确保存在 Documents 文件夹中

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

【问题讨论】:

  • 是什么让您认为将其保存在库文件夹中会显示在 Files App 上?
  • 我不知道,我从研究中猜到了这个
  • 你的问题是什么?
  • 我只想在“文件”应用中显示文件

标签: swift xcode


【解决方案1】:

如果您想在 Apple 的 Files App 中公开您的 App 文档文件,您需要在 info plist 文件中包含 "Supports Document Browser" 键并将其设置为 YES:

【讨论】:

    【解决方案2】:

    要设置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

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多