【发布时间】:2020-04-15 13:03:28
【问题描述】:
我有一个简单的 UIDocument 子类,它覆盖了 load 和 contents 函数。
在 iOS 13 更新之前,json 文档保存在 url "/private/var/mobile/Library/Mobile Documents/iCloud~appbundle/Documents/EFB7FCBA96684AC0B101E3CD829E6996.json"中
在当前 iOS 版本 13.2.2(更新后)中,此文档无法打开:
let cloudDocument: ICloudDocument = ICloudDocument(fileURL: url)
cloudDocument.open { (openSuccess) in
if openSuccess {
success()
} else {
// in my case openSuccess is false
failure()
}
}
调试信息。
在 ICloudDocument 中覆盖 handleError 之后
override func handleError(_ error: Error, userInteractionPermitted: Bool) {
print("userInteractionPermitted - \(userInteractionPermitted)")
print(error)
}
在控制台中:
userInteractionPermitted - true
Error Domain=NSCocoaErrorDomain Code=256 "The file “EFB7FCBA96684AC0B101E3CD829E6996” couldn’t be opened." UserInfo={NSURL=file:///private/var/mobile/Library/Mobile%20Documents/iCloud~appbundle/Documents/EFB7FCBA96684AC0B101E3CD829E6996.json}
如果我在 ICloudDocument 中使用 cloudDocument.read 方法,它可以很好地从文件接收数据,但 open 会引发错误。
DocumentState cloudDocument.documentState 的文档已关闭。
文件选项:
> print(FileManager.default.isWritableFile(atPath: url.path))
true
> print(FileManager.default.isReadableFile(atPath: url.path))
true
URLResourceKeys:
URLResourceKey.ubiquitousItemIsUploadingKey - true
URLResourceKey.ubiquitousItemIsUploadedKey - false
URLResourceKey.ubiquitousItemUploadingErrorKey - nil
URLResourceKey.ubiquitousItemHasUnresolvedConflictsKey - false
URLResourceKey.isUbiquitousItemKey - true
URLResourceKey.ubiquitousItemDownloadingStatusKey - "NSURLUbiquitousItemDownloadingStatusCurrent"
我发现一个关于这个问题的链接没有答案 https://forums.developer.apple.com/thread/126889
有什么想法吗?
【问题讨论】:
标签: ios swift icloud uidocument icloud-documents