I am trying to get a phone number from the contacts picker. My problem is that the identifier provided by the shouldContinueAfterSelectingPerson function is not consistent and is causing the app to crash.
Here is the code for that function:
The problem is that when I choose the first phone number listed for the contact person sometimes the identifier is given as a "0" and sometimes it is given as a "1" and sometimes a "2".
So when I try and run the command:
The app will crash if the identifier is given as a "2" and there is only one phone number. It is trying to access an object at index 2 when it does not exist.
Why would I be getting back a bad identifier number?
Please keep in mind this is my first dealing with the contact list so I may be completely missing something here.
Thanks
Here is the code for that function:
Code:
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier{
NSLog(@"Here ident[%d]", identifier);
ABMultiValueRef container = ABRecordCopyValue(person, property);
CFStringRef contactData = ABMultiValueCopyValueAtIndex(container, identifier);
CFRelease(container);
NSString *contactString = [NSString stringWithString:(NSString *)contactData];
CFRelease(contactData);
NSLog(@"PhoneNumber[%@]", contactString);
[self dismissModalViewControllerAnimated:YES];
return NO;
}
The problem is that when I choose the first phone number listed for the contact person sometimes the identifier is given as a "0" and sometimes it is given as a "1" and sometimes a "2".
So when I try and run the command:
Code:
CFStringRef contactData = ABMultiValueCopyValueAtIndex(container, identifier);
The app will crash if the identifier is given as a "2" and there is only one phone number. It is trying to access an object at index 2 when it does not exist.
Why would I be getting back a bad identifier number?
Please keep in mind this is my first dealing with the contact list so I may be completely missing something here.
Thanks