简体   繁体   English

核心数据不从iCloud下载所有数据

[英]Core Data not downloading all data from iCloud

I've been using Core Data in one of my projects for about 6 months now, all working fine, until the other day when a user reported that some of the data from her iOS device wasn't being synced onto her Mac. 我已经在我的一个项目中使用Core Data大约6个月了,一切正常,直到有一天用户报告她的iOS设备中的一些数据没有被同步到她的Mac上。

When I checked it out it seems that some NSManagedObjects hadn't been imported by the Mac, although they seemed to have been uploaded to iCloud by the iOS device. 当我查看它时,似乎某些NSManagedObjects尚未被Mac导入,尽管它们似乎已被iOS设备上传到iCloud。

I managed to fix the issue by rebuilding the persistent store from iCloud, by passing through the NSPersistentStoreRebuildFromUbiquitousContentOptions with a value of @YES when adding the iCloud enabled persistent store to the persistent store coordinator. 我设法通过在向持久性存储协调器添加启用iCloud的持久性存储时,通过传递值为@YESNSPersistentStoreRebuildFromUbiquitousContentOptions来重建iCloud中的持久存储来解决此问题。

I would like to know if this is a known issue and if it's preventable? 我想知道这是否是一个已知问题,是否可以预防? Unfortunately I don't have any error reports. 不幸的是,我没有任何错误报告。

I have the same problem and solved it by removing the persistentStore and adding it again while the app is running. 我有同样的问题,通过删除persistentStore并在应用程序运行时再次添加它来解决它。 It is always the same problem when doing several changes in the first device, the second device doesn't get all the changes. 在第一个设备中进行多次更改时始终存在同样的问题,第二个设备未获得所有更改。 I use the following code when applicationDidBecomeActive to remove the persistent store first: applicationDidBecomeActive首先删除持久存储时,我使用以下代码:

var storeCoordinator:NSPersistentStoreCoordinator = persistentStoreCoordinator!
        var store:NSPersistentStore = storeCoordinator.persistentStores[0] as! NSPersistentStore
        var storeURL:NSURL = store.URL!
        storeCoordinator.removePersistentStore(store, error: nil)
        NSFileManager.defaultManager().removeItemAtPath(storeURL.path!, error: nil)

Following I proceed to add the persistentStore again. 接下来我再次添加persistentStore。 Then I received all the notifications as it was the first run after installation but with the full data synched. 然后我收到了所有通知,因为它是安装后的第一次运行,但同步完整数据。 it always works but I don't know if it is the proper way to handle the problem. 它总是有效,但我不知道这是否是处理问题的正确方法。

I believe that all the changes made in the first device always reach the second device but for some weird reason they don't merge completely with the local core data. 我相信在第一个设备中所做的所有更改总是到达第二个设备,但由于一些奇怪的原因,它们不会完全与本地核心数据合并。 I have made some weird observations about the iCloud-CoreData issue in: https://stackoverflow.com/questions/32084952/core-data-to-icloud-doesnt-sync-all-changes][1] 我在以下网址中对iCloud-CoreData问题做了一些奇怪的观察: https ://stackoverflow.com/questions/32084952/core-data-to-icloud-doesnt-sync-all-changes ] [1]

I hope it helps. 我希望它有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM