I am developing an iPhone app that opens the user's address book, it fetches the phone number of a person that user has selected from phone book. In case if the Address Book has a person having 2 or more phone numbers and user deletes one of the contacts,and after that user selects the contact from that person ,then the "ABPeoplePickerNavigationControllerDelegate" method -
(void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier NS_AVAILABLE_IOS(8_0);
gives wrong identifier.Else it is working fine.
Here is the code,that i am using to fetch the selected phone number from the address book.Does anyone have any idea why the delegate method isn't giving the correct identifier?
- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier
{
if (property == kABPersonPhoneProperty)
{
NSString* phoneNumber = nil;
ABMultiValueRef phoneNumbers = ABRecordCopyValue(person,
property);
if (ABMultiValueGetCount(phoneNumbers) > 0)
{
CFIndex index = ABMultiValueGetIndexForIdentifier(phoneNumbers, identifier);
*//**** since identifier is wrong it returns index as -1 and app crashes in the below line *****
phoneNumber = (__bridge_transfer NSString*) ABMultiValueCopyValueAtIndex(phoneNumbers, index);
}
}