【发布时间】:2019-10-25 17:57:13
【问题描述】:
我正在为 Mac Catalyst 应用寻找除 UIActivityViewController 之外的替代导出菜单。虽然这可行,但用户无法选择他们想要保存文件的位置(文件是列表中所有项目的 JSON 文件),我希望用户能够选择他们想要保存 JSON 的目录到。我尝试了以下代码,但是当您尝试保存文件时,它给出了错误“错误域 = NSCocoaErrorDomain 代码 = 260 '无法打开文件'name.json',因为没有这样的文件'”。
代码:
let fileManager = FileManager.default
do {
let fileURL2 = fileManager.temporaryDirectory.appendingPathComponent("\(detailedList.lname!).json")
// Write the data out into the file
try jsonData.write(to: fileURL2)
// Present the save controller. We've set it to `exportToService` in order
// to export the data -- OLD COMMENT
let controller = UIDocumentPickerViewController(url: fileURL2, in: UIDocumentPickerMode.exportToService)
present(controller, animated: true) {
// Once we're done, delete the temporary file
try? fileManager.removeItem(at: fileURL2)
}
} catch {
print("error creating file")
}
我已经尝试使用谷歌搜索其他方式或方法来使其工作,但我找不到任何可以在 Mac Catalyst 上工作的东西。我知道您可以这样做,因为我已经看到其他应用程序和示例可以做到这一点,但对我没有任何帮助。那么有什么可能的替代方法来执行此操作或此代码的解决方案?
【问题讨论】:
标签: ios swift uiactivityviewcontroller uidocumentpickerviewcontroller mac-catalyst