【问题标题】:iCloud UIDocument opening fails after update on iOS 13在 iOS 13 上更新后,iCloud UIDocument 打开失败
【发布时间】:2020-04-15 13:03:28
【问题描述】:

我有一个简单的 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()
    }
}

调试信息。

在 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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2019-10-12
      • 1970-01-01
      • 2013-07-29
      • 1970-01-01
      • 2014-03-08
      • 1970-01-01
      • 2022-06-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多