iOS 9 CoreData / ICloud - URL 处没有此类文档

iOS 9 CoreData / ICloud - No such document at URL

更新 2

我偶尔也会遇到这个错误:

CoreData: Ubiquity:  Librarian returned a serious error for starting downloads Error Domain=BRCloudDocsErrorDomain Code=6

不知是否有关联?正在努力提交错误报告,但不胜感激任何见解。

更新

发生此错误时,coredata 出现非常奇怪的行为,它将无法在同一上下文中找到相关对象。现在这绝对是我的应用程序瘫痪

原始问题

我有一个应用程序似乎在 90% 的时间里都能完美地工作,将 CoreData 与 iCloud 无处不在的存储同步。

有时我收到此错误,事情开始变得有点疯狂:

CoreData: Ubiquity:  Librarian returned a serious error for starting downloads Error Domain=BRCloudDocsErrorDomain Code=5 "No document at URL"

我已经搜索过有关如何解决此问题的信息,但我没有看到任何可以帮助我解决已发布的其他问题的信息。许多人只是简单地说他们只是放弃了修复它的尝试。

任何人都可以看到我的核心数据堆栈有任何问题会导致这种情况吗?!我觉得我在吃疯狂的药。

// MARK: - Core Data stack

lazy var managedObjectModel: NSManagedObjectModel = {
    // The managed object model for the application. This property is not optional. It is a fatal error for the application not to be able to find and load its model.
    let modelURL = NSBundle.mainBundle().URLForResource("Model", withExtension: "momd")!
    return NSManagedObjectModel(contentsOfURL: modelURL)!
    }()

lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator? = {
    // The persistent store coordinator for the application. This implementation creates and return a coordinator, having added the store for the application to it. This property is optional since there are legitimate error conditions that could cause the creation of the store to fail.
    // Create the coordinator and store
    var coordinator: NSPersistentStoreCoordinator? = NSPersistentStoreCoordinator(managedObjectModel: self.managedObjectModel)


    let documentsDirectory = NSFileManager.defaultManager().URLsForDirectory(NSSearchPathDirectory.DocumentDirectory, inDomains: NSSearchPathDomainMask.UserDomainMask).last as NSURL!

    let storeURL = documentsDirectory.URLByAppendingPathComponent("ArrivedAlive.sqlite")

    var error: NSError? = nil
    var failureReason = "There was an error creating or loading the application's saved data."
    let storeOptions = [NSPersistentStoreUbiquitousContentNameKey: "ArrivedAliveStore", NSMigratePersistentStoresAutomaticallyOption: true, NSInferMappingModelAutomaticallyOption: true]

    do {
        try coordinator!.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: storeURL, options: storeOptions)
    } catch var error1 as NSError {
        error = error1
        coordinator = nil
        // Report any error we got.
        var dict = [String: AnyObject]()
        dict[NSLocalizedDescriptionKey] = "Failed to initialize the application's saved data"
        dict[NSLocalizedFailureReasonErrorKey] = failureReason
        dict[NSUnderlyingErrorKey] = error
        error = NSError(domain: "YOUR_ERROR_DOMAIN", code: 9999, userInfo: dict)
        // Replace this with code to handle the error appropriately.
        // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
        NSLog("Unresolved error \(error), \(error!.userInfo)")
        abort()
    } catch {
        fatalError()
    }

    return coordinator
    }()


lazy var managedObjectContext: NSManagedObjectContext? = {
    // Returns the managed object context for the application (which is already bound to the persistent store coordinator for the application.) This property is optional since there are legitimate error conditions that could cause the creation of the context to fail.
    let coordinator = self.persistentStoreCoordinator
    if coordinator == nil {
        return nil
    }
    var managedObjectContext = NSManagedObjectContext(concurrencyType: NSManagedObjectContextConcurrencyType.MainQueueConcurrencyType)

    managedObjectContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy
    managedObjectContext.persistentStoreCoordinator = coordinator

    return managedObjectContext
    }()

对于那些在这些问题上苦苦挣扎的人 - 让我告诉你们一些好消息:

要解决此问题,请执行以下步骤:

  1. 下载并实施 Ensembles GitHub
  2. 向您的 appDelegate 添加非常少量的代码来创建和管理集成对象
  3. 大声说出你被压抑的挫败感 - 你完成了。

它修复了所有云同步错误

它就像魔法一样有效,我非常高兴。它基本上就像核心数据和 iCloud 之间的中间人一样工作,以确保没有人在思想中发作。