0

我有一个简单的 UIDocument 子类,具有覆盖loadcontents功能。

在 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()
    }
}

调试信息。

handleError在 iCloudDocument 中覆盖后

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}

如果我cloudDocument.read在 ICloudDocument 中使用方法,它可以很好地从文件接收数据,但open会引发错误。

DocumentStatecloudDocument.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

有任何想法吗?

4

1 回答 1

0

重启 iOS 解决了这个问题。我认为更新到 iOS 13 并迁移后,系统需要额外重新加载。

于 2020-01-09T13:30:34.050 回答