Iphone 应用程序在带有iCloud的addPersistentStoreWithType上暂停
我的persistentStoreCoordinator中有以下代码。如果没有iCloud部分,它可以正常工作。对于iCloud,它在addPersistentStoreWithType方法上停止。没有错误,它只是在上面停止,不会继续 有什么想法吗Iphone 应用程序在带有iCloud的addPersistentStoreWithType上暂停,iphone,ios,objective-c,core-data,icloud,Iphone,Ios,Objective C,Core Data,Icloud,我的persistentStoreCoordinator中有以下代码。如果没有iCloud部分,它可以正常工作。对于iCloud,它在addPersistentStoreWithType方法上停止。没有错误,它只是在上面停止,不会继续 有什么想法吗 - (NSPersistentStoreCoordinator *)persistentStoreCoordinator { if (_persistentStoreCoordinator != nil) { return _
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
if (_persistentStoreCoordinator != nil) {
return _persistentStoreCoordinator;
}
NSURL *storeURL = [NSURL fileURLWithPath:STORE_PATH];
_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSMutableDictionary *options = [NSMutableDictionary dictionary];
[options setObject:[NSNumber numberWithBool:YES] forKey:NSMigratePersistentStoresAutomaticallyOption];
[options setObject:[NSNumber numberWithBool:YES] forKey:NSInferMappingModelAutomaticallyOption];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *iCloud = [fileManager URLForUbiquityContainerIdentifier:nil];
NSLog(@"icloud: %@", iCloud);
if (iCloud) {
NSString *iCloudLogsDirectoryName = @"Logs";
NSURL *iCloudLogsPath = [NSURL fileURLWithPath:[[iCloud path] stringByAppendingPathComponent:iCloudLogsDirectoryName]];
//Create logs directory, in case it doesn't exist
if([fileManager fileExistsAtPath:[iCloudLogsPath path]] == NO) {
NSLog(@"logs directory doesn't exist");
NSError *fileSystemError;
[fileManager createDirectoryAtPath:[[iCloud path] stringByAppendingPathComponent:iCloudLogsDirectoryName]
withIntermediateDirectories:YES
attributes:nil
error:&fileSystemError];
if(fileSystemError != nil) {
NSLog(@"Error creating logs directory %@", fileSystemError);
}
}
NSString *iCloudEnabledAppID = @"app id removed from stackoverflow";
[options setObject:iCloudEnabledAppID forKey:NSPersistentStoreUbiquitousContentNameKey];
[options setObject:iCloudLogsPath forKey:NSPersistentStoreUbiquitousContentURLKey];
NSLog(@"logs path: %@", iCloudLogsPath);
}
[_persistentStoreCoordinator lock];
NSError *error;
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil
URL:storeURL
options:options
error:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
else {
NSLog(@"done adding persistent store");
}
[_persistentStoreCoordinator unlock];
dispatch_async(dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:@"SomethingChanged" object:self userInfo:nil];
[self.delegate contextWasSetupInManager:self];
});
});
return _persistentStoreCoordinator;
}
这在iCloud中很常见。苹果建议你把它放在后台队列中,因为那个电话可能会被阻塞。它之所以会阻塞,是因为核心数据实际上是在这里连接到iCloud服务器,并开始下载任何可用的新数据。通话结束后才继续。如果有大量数据需要下载,您可以等待一段时间 有时它需要一段时间,没有明显的原因。像那样的薄片
最终,你所看到的与iCloud目前的情况差不多。提交一两个bug,并希望情况有所改善 我刚刚在一台测试设备(运行iOS 6.1的iPhone 5)上体验到了这一点。进行出厂重置,然后从手机的当前备份中恢复,修复了此问题 我不确定这是否是解释,但通过设备设置>iCloud>存储和备份删除应用程序的iCloud ubiquity容器数据似乎存在问题。这可能会使设备处于这样一种状态,即ubiquity容器的一些残余物仍然存在,并且无法移除。在设备上执行完全擦除和恢复似乎可以解决此问题 我在OpenRadar()上发现了一篇与此问题()相关的旧帖子。我把它弄得一团糟了好几个小时,直到我擦除并恢复了这个设备,它工作得非常好:addPersistentStoreWithType几乎立即完成
接下来,我将尝试在WWDC 2012示例应用程序SharedCodeData(会话227)中使用nukeAndPave方法清除存储,而不是从设置中手动删除存储。希望这能防止这种情况再次发生。我不太清楚为什么会出现这些问题,但我通过重置手机设置成功地解决了此类问题:
设置>常规>重置>重置所有设置在后台运行此方法的情况下,我能否允许用户继续使用我的应用程序中的核心数据?不幸的是,否。您可以让此方法运行,只要它需要运行,但在它完成之前,您没有数据存储。这意味着您无法从核心数据中获取任何信息。关于如何处理这个问题,我已经看到了一些想法,但没有一个是真正成功的。但这不是。。破坏我的用户体验,iCloud可以花它想要的时间(分钟、小时)让用户保持在同一点上,而不让他们以其他方式使用应用程序?肯定有办法解决这个问题,一个替代方案?是的,这对你的用户体验来说是个问题。至于替代方案,我已经研究了一段时间的替代方案,但还没有达到发布一个包含核心数据+iCloud的应用程序的程度。你可能想考虑其他方法——或者准备好用自己的创造性方法来获得核心数据+ iCloud不吸吮。