簡體   English   中英

iOS Core Data iCloud同步-可選

[英]iOS Core Data iCloud sync - make optional

我想將iCloud同步添加到基於CoreData的應用程序中,並使其成為選項而非唯一狀態。 據我所知,在iOS 7+中添加iCloud歸結為添加

@{NSPersistentStoreUbiquitousContentNameKey: @"MyCloudStore"}

選項字典,以addPersistentStoreWithType:...調用,並通過合並傳入的數據來響應NSPersistentStoreDidImportUbiquitousContentChangesNotification

這是否意味着要在應用程序中啟用/禁用iCloud同步,我只需要使用適當的選項將商店重新添加到persistentStoreCoordinator ,然后添加/刪除NSPersistentStoreDidImportUbiquitousContentChangesNotification觀察者? 使用相同的本地SQLite文件會出現問題嗎?

不,這還不夠,您還需要對NSPersistentStoreCoordinatorStoresWillChangeNotification和NSPersistentStoreCoordinatorStoresDidChangeNotification做出反應。

另外,您還需要反映您的功能,例如,如果您有初始數據,則需要考慮將應用程序安裝在第二個設備/對等設備上時發生了什么,以避免重復數據。

此外,您需要檢查帳戶是否更改,以及其他一些問題。

蘋果提供了一個很好的文檔, 網址為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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM