So basically what we can do here is to verify the thread handling that we might have like
dispatch_async calls.
Do you suggest that restkit calls should not be put inside dispatch_async calls? Here's a snippet of my code that usually crashes with the same error:
-(void) syncContactsViaRestKit{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *vmsgUserId = [defaults stringForKey:@"vmsgUserId"];
BOOL initialSync = [defaults boolForKey:@"initialSync"];
BOOL sync = [defaults boolForKey:@"sync_preferences"];
if(initialSync){
[defaults setBool:NO forKey:@"initialSync"];
[defaults synchronize];
HUD = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
HUD.delegate = self;
HUD.mode = MBProgressHUDModeIndeterminate;
}
if(sync){
HUD.labelText = @"Synchronize Contacts...";
}else{
HUD.labelText = @"Retrieving Server Contacts...";
}
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
NSMutableArray *contacts;
if (sync) {
contacts = [self getPhoneContacts];
}
dispatch_async(dispatch_get_main_queue(), ^{
if(sync){
if(contacts == nil){
HUD.labelText = @"Cannot retrieve contacts...";
[HUD hide:YES afterDelay:1];
[CustomAlertView showCustomPop:CustomAlertViewTypeSingle inView:self.view WithFrame:self.view.frame Title:@"Alert" Message:@"Please allow app to retrieve contacts for sync via Settings app > Privacy > Contacts > App > On" actionButtonTitle:@"Ok" action:@selector(doSomething) cancelButtonTitle:nil];
}else{
NSError *error = nil;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:contacts options:NSJSONWritingPrettyPrinted error:&error];
if ([jsonData length] > 0 && error == nil) {
[self sendRestkitSyncRequestWithUserId:vmsgUserId withContactsPayload:jsonData];
}
}
}else{
[self sendRestkitSyncRequestWithUserId:vmsgUserId withContactsPayload:nil];
}
});
});
}
-(void)objectLoader:(RKObjectLoader *)objectLoader didLoadObjects:(NSArray *)objects{
NSLog(@"Load collection of Contacts: %@", objects);
NSLog(@"Object Size: %d", objects.count);
NSArray *cont = [Contacts allObjects];
for(Contacts *contact in cont){
if(![objects containsObject:contact]){
NSLog(@"Delete the contact : %@ withID: %@ ;because it is not anymore in the new list from server..",
contact.name, contact.vmsgUserId);
[[[[RKObjectManager sharedManager] objectStore] managedObjectContextForCurrentThread] deleteObject:contact];
}
}
//Saving changes in MOC
NSError* error = nil;
[[[[RKObjectManager sharedManager] objectStore] managedObjectContextForCurrentThread] save:&error];
[HUD hide:YES];
}
Here is a snippet of the crash report: