这是我在init存储类使用的代码,它工作得很好,直到最近..当我尝试测试它,它崩溃(下标)在addPersistentStoreWithType ......我注意到这个切换到iPhone 5后,并试图运行应用程序......但如果我关闭的icloud我的手机上或测试上不存在任何问题的模拟器...
-(id)init
{
self = [super init];
if(self)
{
NSLog(@"%s", __FUNCTION__);
favColors = [[NSMutableArray alloc] init];
model = [NSManagedObjectModel mergedModelFromBundles:nil];
NSPersistentStoreCoordinator *psc = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model];
NSString *path = [self itemArchivePath];
NSURL *storeURL = [NSURL fileURLWithPath:path];
NSError *error = nil;
NSMutableDictionary *options = [NSMutableDictionary dictionary];
NSURL *ubiq = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
if (ubiq) {
NSLog(@"iCloud access at %@", ubiq);
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(contentChange:) name:NSPersistentStoreDidImportUbiquitousContentChangesNotification object:nil];
NSFileManager *fm = [NSFileManager defaultManager];
NSURL *ubcontainer = [fm URLForUbiquityContainerIdentifier:nil];
[options setObject:@"color" forKey:NSPersistentStoreUbiquitousContentNameKey];
[options setObject:ubcontainer forKey:NSPersistentStoreUbiquitousContentURLKey];
} else {
NSLog(@"No iCloud access");
}
// ************ Crash here **************
if (![psc addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:(ubiq?options:nil) error:&error]) {
[NSException raise:@"Open failed" format:@"Reason: %@", [error localizedDescription]];
}
context = [[NSManagedObjectContext alloc] init];
[context setPersistentStoreCoordinator:psc];
[context setUndoManager:nil];
[self loadAllItems];
}
return self;
}
- (NSString *)itemArchivePath
{
NSArray *documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [documentDirectories objectAtIndex:0];
return [documentDirectory stringByAppendingPathComponent:@"store.data"];
}
另外,如果我一旦运行应用程序和崩溃后关闭iCloud中并再次运行该应用程序。该数据是从icloud的检索...并显示在应用程序。
该出把日志显示这一点。
在文件的iCloud访问://本地主机/私营/无功/移动/图书馆/移动%20Documents / XXX -PFUbiquitySetupAssistant performPreStoreSetupWithError :: CoreData:普遍性:基线文件存在,但不能读