【发布时间】:2021-04-07 11:14:45
【问题描述】:
下面的代码在 iPad 或 iPhone 上运行良好—— saveDocument()(见下文)写入 /Users/me/Library/Containers/My-App/Data/Documents,而 openDocument() 显示内容那个文件夹。
然而,在 macOS 上,openDocument() 会在 iCloud Drive 的根级别显示 Documents 文件夹,而不是我计算机本地的沙盒版本
这就像 documentPickerVC.directoryURL 被忽略了。这是为什么呢?
如果有帮助,documentURL 如下所示:
file:///Users/me/Library/Containers/org.me.My-App/Data/Documents/
任何帮助都会非常非常感谢!
func saveDocument(){
let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted
do {
let puzzleData = try? encoder.encode(puzzle)
print("Saving: \(documentURL)")
let saveableURL = documentURL!.appendingPathComponent("\( .puzzle.date)")
try puzzleData!.write(to: saveableURL)
} catch {
displayError(title: "Error while saving document", message: "There was an error: \(error)")
}
}
// when the user taps on the Open button
@objc func openDocument(){
documentPickerVC = UIDocumentPickerViewController(forOpeningContentTypes: [UTType("public.item")!, UTType("public.data")!], asCopy: true )
documentPickerVC.delegate = self
documentPickerVC.modalPresentationStyle = .formSheet
documentPickerVC.directoryURL = documentURL
self.present(documentPickerVC, animated: true)
}
【问题讨论】:
-
在我的情况下,当执行
self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:targetURL];崩溃:由于未捕获的异常“NSGenericException”而终止应用程序,原因:“UIDocumentInteractionController 不可用”。你怎么能解决这个问题?
标签: macos catalyst uidocumentpickerviewcontroller