【问题标题】:How to handle NSPersistentStoreCoordinatorStoresWillChangeNotification when store locations are identical当商店位置相同时如何处理 NSPersistentStoreCoordinatorStoresWillChangeNotification
【发布时间】:2015-01-29 17:58:04
【问题描述】:

我正在使用 Core Data + iCloud 并获得不少 NSPersistentStoreCoordinatorStoresWillChangeNotifications,其中新旧商店的 URL 是相同的。我只使用一台设备,并且在运行我的应用程序时会发生多次。

如果商店 URL 没有更改,并且设备是唯一将数据保存到商店的设备,为什么会发出这些通知?当新旧网址相同时,这些通知可以忽略吗?

这里是通知的 userInfo 字典的内容:

NSConcreteNotification 0x17a5f6b0 {name = NSPersistentStoreCoordinatorStoresWillChangeNotification; object = <NSPersistentStoreCoordinator: 0x167e05c0>; userInfo = {
NSPersistentStoreUbiquitousTransitionTypeKey = 4;
added =     (
    "<NSSQLCore: 0x1787bcf0> (URL: file:///var/mobile/Containers/Data/Application/8D9D2E83-DCD6-427B-BF5B-371D6DFD1999/Documents/CoreDataUbiquitySupport/mobile~38BB3D02-34D8-4E44-BCBE-B3ACC4FFA2DC/QatQiGameData3/8FD336B2-35D5-4D5F-8B06-415C7CA523CB/store/qatqi.sqlite)"
);
removed =     (
    "<NSSQLCore: 0x1787bcf0> (URL: file:///var/mobile/Containers/Data/Application/8D9D2E83-DCD6-427B-BF5B-371D6DFD1999/Documents/CoreDataUbiquitySupport/mobile~38BB3D02-34D8-4E44-BCBE-B3ACC4FFA2DC/QatQiGameData3/8FD336B2-35D5-4D5F-8B06-415C7CA523CB/store/qatqi.sqlite)"
);

}}

【问题讨论】:

    标签: ios core-data icloud nspersistentstore


    【解决方案1】:

    数字“4”对应于“NSPersistentStoreUbiquitousTransitionType.InitialImportCompleted”。 Apple 的文档指出:

    此值表示 Core Data 集成已完成构建与 iCloud 帐户内容一致的存储文件,并准备用该文件替换备用存储。

    fallback store 和 ubiquity (iCloud) store 确实有相同的 URL,所以 URL 不会改变。如果您显示的数据在导入时正确更新,那么您可以忽略这些通知。否则,您可能需要更新正在显示的数据。

    【讨论】:

      猜你喜欢
      • 2021-12-30
      • 2016-01-27
      • 2015-07-26
      • 1970-01-01
      • 2019-09-03
      • 1970-01-01
      • 1970-01-01
      • 2016-03-07
      • 2021-10-22
      相关资源
      最近更新 更多