iOS 9 CoreData / ICloud – URL中没有这样的文档
更新2
我也偶尔得到这个错误:
CoreData: Ubiquity: Librarian returned a serious error for starting downloads Error Domain=BRCloudDocsErrorDomain Code=6
我想知道它是否相关? 我正在努力提交一个错误报告,但将不胜感激。
UPDATE
当这个错误发生时,我得到了非常奇怪的行为与coredata,它将无法在相同的上下文中find相关的对象。 这是现在绝对削弱我的应用程序
原文问题
我有一个应用程序似乎90%的时间同步CoreData与iCloud Ubiquitous存储的时间。
有时我收到这个错误,事情开始有点疯狂:
CoreData: Ubiquity: Librarian returned a serious error for starting downloads Error Domain=BRCloudDocsErrorDomain Code=5 "No document at URL"
我已经search了解如何解决这个问题,但我没有看到任何东西来帮助我已经发布的其他问题。 很多人只是说他们只是放弃了试图解决这个问题。
任何人都可以看到我的核心数据堆栈会导致这个问题? 我觉得我正在服用疯狂的药丸。
// 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 }()
对于那些在这些问题上挣扎的人,让我给你一些好消息:
要解决问题,请按照下列步骤操作:
- 下载并实施Ensembles GitHub
- 添加非常less量的代码到你的appDelegate来创build和pipe理整体对象
- 哭出来你被压抑的挫折 – 你完成了。
它固定所有云同步错误
它只是像魔术一样工作,我不能更快乐。 它本质上是一个核心数据和iCloud之间的中间人,以确保没有人在中间思考。