简体   繁体   English

核心数据+ iCloud Sync NSPersistentStoreDidImportUbiquitousContentChangesNotification

[英]Core data + iCloud Sync NSPersistentStoreDidImportUbiquitousContentChangesNotification

I'm experiencing some wired behavior with core data and iCloud sync. 我正在经历核心数据和iCloud同步的一些有线行为。 I added the iCloud documents and Cloudkit capabilities to my app and I subscribed to these three notifications: 我在我的应用程序中添加了iCloud文档和Cloudkit功能,并订阅了这三个通知:

NSPersistentStoreCoordinatorStoresWillChangeNotification
NSPersistentStoreCoordinatorStoresDidChangeNotification
NSPersistentStoreDidImportUbiquitousContentChangesNotification

The first time I ran the app I received these notifications: 我第一次运行应用程序时收到了这些通知:

Using local storage: 1
store will Change notification
store did Change notification
Using local storage: 0

but, NSPersistentStoreDidImportUbiquitousContentChangesNotification didn't get fired because core data did not download data from the ubiquitous container of my iCloud account. 但是,NSPersistentStoreDidImportUbiquitousContentChangesNotification没有被解雇,因为核心数据没有从我的iCloud帐户无处不在的容器中下载数据。

However, when I exited the app and relaunched it even with airplane mode turned on, all my data got loaded immediately. 但是,当我退出应用程序并在启用飞行模式时重新启动它时,我的所有数据都立即加载。 It seemed that the data were downloaded and saved to SQLite store on the first launch but the notification wasn't fired so that my UI can be refreshed. 似乎第一次启动时数据已下载并保存到SQLite存储,但未通知通知,因此我的UI可以刷新。

Have anyone experienced such before and what did you do in that situation. 有没有人经历过这样的事情,你在那种情况下做了什么。

There's a difference between first-time setup and 'normal' sync operations. 首次设置和“正常”同步操作之间存在差异。

The NSPersistentStoreDidImportUbiquitousContentChangesNotification is not posted during the first-time setup; 在首次设置期间不会发布NSPersistentStoreDidImportUbiquitousContentChangesNotification ; only when changes later happen. 只有在以后发生变化时。 This notifies the app to import them (by calling mergeChangesFromContextDidSaveNotification(_:) ). 这会通知应用程序导入它们(通过调用mergeChangesFromContextDidSaveNotification(_:) )。

Apple's iCloud Programming Guide for CoreData is quite helpful for understanding what happens at which stage. Apple的CoreData iCloud编程指南非常有助于理解在哪个阶段发生的事情。

See especially the chapters on iCloud Performs a One-Time Setup and Core Data Posts Content Changes from iCloud . 请特别参阅有关iCloud的章节,从iCloud执行一次性设置核心数据发布内容更改

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

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