I am building an app using objective-c. when I press button that linked to func that should open the contact of the device I get the following error and the app crashes:
plugin com.apple.MobileAddressBook.ContactsViewService interrupted Hub connection error Error Domain=NSCocoaErrorDomain Code=4097 "The operation couldn’t be completed.... uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
It's important to say that it is not always happen.. sometimes the contacts open and sometimes I get the above error.
here is my code to open the contacts:
- (IBAction)addContacts:(id)sender {
self.user = [[User alloc] init];
NSLog(@"ADD CONTACT");
_addressBookController = [[ABPeoplePickerNavigationController alloc] init];
[_addressBookController setPeoplePickerDelegate:self];
[self presentViewController:_addressBookController animated:YES completion:nil];
}
can someone PLEASE point me to the problem?
I add the peoplePickerNavigationController:
- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person{
NSLog(@"PEOPLE PICKER");
CFTypeRef generalCFObject = ABRecordCopyValue(person, kABPersonFirstNameProperty);
if (generalCFObject) {
self.user.firstName = (__bridge NSString *)generalCFObject;
CFRelease(generalCFObject);
}
generalCFObject = ABRecordCopyValue(person, kABPersonLastNameProperty);
if (generalCFObject) {
self.user.lastName = (__bridge NSString *)generalCFObject;
CFRelease(generalCFObject);
}
ABMultiValueRef phonesRef = ABRecordCopyValue(person, kABPersonPhoneProperty);
for (int i=0; i<ABMultiValueGetCount(phonesRef); i++) {
CFStringRef currentPhoneLabel = ABMultiValueCopyLabelAtIndex(phonesRef, i);
CFStringRef currentPhoneValue = ABMultiValueCopyValueAtIndex(phonesRef, i);
if (CFStringCompare(currentPhoneLabel, kABPersonPhoneMobileLabel, 0) == kCFCompareEqualTo) {
self.user.phoneNumber = (__bridge NSString *)currentPhoneValue;
}
CFRelease(currentPhoneLabel);
CFRelease(currentPhoneValue);
}
CFRelease(phonesRef);
[self.assignment.usersList addObject:self.user];
[self.tableViewCell reloadData];
[_addressBookController dismissViewControllerAnimated:YES completion:nil];
}
-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier{
return NO;
}
//enable contact cancel buttopn
-(void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker{
[_addressBookController dismissViewControllerAnimated:YES completion:nil];
}