[英]iOS Core Data iCloud sync - make optional
I'd like to add iCloud syncing to my CoreData based app, and make it an option rather than the only state. 我想将iCloud同步添加到基于CoreData的应用程序中,并使其成为选项而非唯一状态。 From what I see, in iOS 7+ adding iCloud boils down to adding
据我所知,在iOS 7+中添加iCloud归结为添加
@{NSPersistentStoreUbiquitousContentNameKey: @"MyCloudStore"}
Options dictionary to addPersistentStoreWithType:...
call, and responding to NSPersistentStoreDidImportUbiquitousContentChangesNotification
by merging the incoming data. 选项字典,以
addPersistentStoreWithType:...
调用,并通过合并传入的数据来响应NSPersistentStoreDidImportUbiquitousContentChangesNotification
。
Does this mean that to enable/disable iCloud syncing in the app, I just need to re-add the store to the persistentStoreCoordinator
with the appropriate options and add/remove the NSPersistentStoreDidImportUbiquitousContentChangesNotification
observer? 这是否意味着要在应用程序中启用/禁用iCloud同步,我只需要使用适当的选项将商店重新添加到
persistentStoreCoordinator
,然后添加/删除NSPersistentStoreDidImportUbiquitousContentChangesNotification
观察者? Would there be any issues using the same local SQLite file? 使用相同的本地SQLite文件会出现问题吗?
No, this is not sufficient, you need also to react on the NSPersistentStoreCoordinatorStoresWillChangeNotification and NSPersistentStoreCoordinatorStoresDidChangeNotification . 不,这还不够,您还需要对NSPersistentStoreCoordinatorStoresWillChangeNotification和NSPersistentStoreCoordinatorStoresDidChangeNotification做出反应。
Also you need to reflect your functionality, eg if you have initial data you need to think about what happened when the app will be installed on the 2nd device/peer to avoid duplicate data. 另外,您还需要反映您的功能,例如,如果您有初始数据,则需要考虑将应用程序安装在第二个设备/对等设备上时发生了什么,以避免重复数据。
Additionally you need to check whether or/not the account changes, and some more issues. 此外,您需要检查帐户是否更改,以及其他一些问题。
There is a very good documentation from apple https://developer.apple.com/library/ios/documentation/DataManagement/Conceptual/UsingCoreDataWithiCloudPG/Introduction/Introduction.html#//apple_ref/doc/uid/TP40013491-CH1-SW1 which gives a good description what needs to be considered. 苹果提供了一个很好的文档, 网址为https://developer.apple.com/library/ios/documentation/DataManagement/Conceptual/UsingCoreDataWithiCloudPG/Introduction/Introduction.html#//apple_ref/doc/uid/TP40013491-CH1-SW1给出了很好的描述,需要考虑什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.