我遇到的ABPeoplePickerNavigationController生成僵尸和冻结我的应用程序的麻烦,我尝试了几种方法来初始化,但好歹还是另一个似乎会随机冻结我的应用程序:的ABPeoplePickerNavigationController冻结我的应用程序
if([appDelegate testInternetConnection]){
ABPeoplePickerNavigationController *picker =[[ABPeoplePickerNavigationController alloc] init];
[picker setPeoplePickerDelegate:self];
[self presentViewController:picker animated:YES completion:nil ];
}else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Internet Connection Error" message:@"This App needs internet in order to work, please make sure you are connected to a valid network" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil, nil];
dispatch_async(dispatch_get_main_queue(), ^{
// Display/dismiss your alert
[alert show];
});
}
我不知道我做错了什么,但这是冻结我的应用程序outsite模拟器或当它没有调试的设备。 任何想法为什么?
-Update
这里是我使用的核心数据
#pragma mark Save data to Core Data Safely
-(void) saveData{
NSPersistentStoreCoordinator *mainThreadContextStoreCoordinator = [appDelegate persistentStoreCoordinator];
dispatch_queue_t request_queue = dispatch_queue_create("com.4Postcards.savingData", NULL);
dispatch_async(request_queue, ^{
// Create a new managed object context
// Set its persistent store coordinator
NSManagedObjectContext *newMoc = [[NSManagedObjectContext alloc] init];
[newMoc setPersistentStoreCoordinator:mainThreadContextStoreCoordinator];
// Register for context save changes notification
NSNotificationCenter *notify = [NSNotificationCenter defaultCenter];
[notify addObserver:self
selector:@selector(mergeChanges:)
name:NSManagedObjectContextDidSaveNotification
object:newMoc];
// Do the work
// Your method here
// Call save on context (this will send a save notification and call the method below)
NSError *error;
BOOL success = [newMoc save:&error];
if (!success)
NSLog(@"%@",error);
// Deal with error
});
}
- (void)mergeChanges:(NSNotification*)notification
{
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"Data Saved");
});
}
保存为我说,现在当运行连接到它的Xcode不冻结的代码,但断开当它
你在你的应用程序使用coredata? – Saad 2014-09-22 22:04:58
为什么你需要互联网来选择联系人? – rmaddy 2014-09-22 22:05:16
您是否尝试过使用调试器来查看您的应用“冻结”的位置? – rmaddy 2014-09-22 22:05:33