ios – iCloud在初始同步期间做了什么?

我想将我的Core Data鞋盒应用程序与iCloud同步. Apple提供的示例项目显示了如何设置NSPersistentStoreCoordinator以启用iCloud.代码大致如下所示:

persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]];

NSDictionary* options = [NSDictionary dictionaryWithObjectsAndKeys:@"com.company.app", NSPersistentStoreUbiquitousContentNameKey, cloudURL, NSPersistentStoreUbiquitousContentURLKey,nil];

[psc addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error]);

问题是:如果已经存储在iCloud中的数据,则此方法将永远返回persistentStoreCoordinator.如果我同步进行,我会看一个空白屏幕几分钟,如果我异步操作我的应用程序完全无法使用,因为我无法与Core Data交互.

当然,我可以像没有iCloud一样添加持久存储,然后让iCloud异步工作?

基本上,我的问题是,iCloud在初始同步期间做了什么,我可以先使用persistentStoreCoordinator,让数据在后台同步吗?

最佳答案 使用iCloud同步Core Data时,需要在单独的线程上加载存储.看一眼:

https://devforums.apple.com/thread/126670

这表明了商店的异步加载.

点赞