【发布时间】:2014-10-07 09:12:16
【问题描述】:
如何在已经使用本地存储核心数据的应用中启用 iCloud 核心数据?
我尝试在我的持久存储选项中使用NSPersistentStoreUbiquitousContentNameKey。不幸的是,此选项启用 iCloud,但不会将任何本地数据传输到 iCloud。我似乎也无法让migratePersistentStore:toURL:options:withType:error: 工作。我提供了持久存储、它的 URL、iCloud 选项等,它仍然不会将现有的本地数据迁移到 iCloud。以下是我使用该方法的方式:
- (void)migratePersistentStoreWithOptions:(NSDictionary *)options {
NSError *error;
self.storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:[NSString stringWithFormat:@"%@.sqlite", self.SQLiteFileName]];
NSPersistentStore *store = [self.persistentStoreCoordinator migratePersistentStore:self.persistentStoreCoordinator.persistentStores.firstObject toURL:self.storeURL options:options withType:NSSQLiteStoreType error:&error];
if (store) NSLog(@"[CoreData Manager] Store was successfully migrated");
else NSLog(@"[CoreData Manager] Error migrating persistent store: %@", error);
}
本地存储与 iCloud 存储保持分离。如果可能,我想将本地核心数据移动到 iCloud,而无需手动传输每个实体。
有什么想法吗?我可以找到很多关于从 iCloud 移回本地存储的文章、教程和帖子 - 但我想从 本地存储移动到 iCloud。
【问题讨论】:
-
“我似乎也无法让 migratePersistentStore:toURL:options:withType:error: 工作。” 具体来说,它在什么方面不起作用?
-
@TomHarrington 查看我最近的编辑。当我调用该方法并指定存储及其 URL 时,没有任何内容被移动 - 本地存储保持不变,而 iCloud 存储保持为空。
标签: ios objective-c cocoa-touch core-data icloud