我有一个在应用程序中创建持久存储的应用程序:didFinishLaunchingWithOptions。添加商店显然需要很长时间,这会导致 iOS 在应用程序完成启动之前终止它。如何将商店添加到主线程之外的协调器?有什么例子吗? 堆栈溢出链接
操作系统版本:iOS 6.1.3 (10B329) 报告版本:104
异常类型:00000020 异常代码:0x000000008badf00d 突出显示的线程:0
应用程序特定信息:com.maksanzhi.person 未能及时启动
已用总 CPU 时间(秒):13.470(用户 13.470,系统 0.000),22% CPU 已用应用程序 CPU 时间(秒):0.343,1% CPU
线程 0 名称:调度队列:com.apple.main-thread 线程 0:
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
if (_persistentStoreCoordinator != nil) {
return _persistentStoreCoordinator;
}
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"COOLPERSONS.sqldata"];
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:[storeURL path]]) {
NSURL *defaultStoreURL = [[NSBundle mainBundle] URLForResource:@"COOLPERSONS" withExtension:@"sqldata"];
if (defaultStoreURL) {
[fileManager copyItemAtURL:defaultStoreURL toURL:storeURL error:NULL];
[self addSkipBackupAttributeToItemAtURL:storeURL];
}
}
NSError *error = nil;
_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
return _persistentStoreCoordinator;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
UINavigationController *nav = (UINavigationController *)self.window.rootViewController;
MainViewController *cvtc = (MainViewController *)[[nav viewControllers]objectAtIndex:0];
cvtc.managedObjectContext = self.managedObjectContext;
[self setAppereance];
return YES;
}