I am trying to give the user the possibility to select a phone number from their Contacts and then display the chosen number in a UITextField.
The problem is that the returned ABMultiValueIdentifier
from shouldContinueAfterSelectingPerson
is always 0 no matter which number you select on a contact.
This is my code:
- (IBAction)btnChooseContactClicked:(id)sender {
[[UINavigationBar appearance] setBackgroundColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
[picker setDisplayedProperties: [NSArray arrayWithObjects: [NSNumber numberWithInt: kABPersonPhoneProperty], nil]];
picker.peoplePickerDelegate = self;
[self presentModalViewController:picker animated:YES];
}
- (void)peoplePickerNavigationControllerDidCancel:
(ABPeoplePickerNavigationController *)peoplePicker
{
[self dismissModalViewControllerAnimated:YES];
}
- (BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person {
return YES;
}
- (BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person
property:(ABPropertyID)property
identifier:(ABMultiValueIdentifier)identifier //Always = 0
{
[self displayPerson:person property:property identifier:identifier];
[self dismissModalViewControllerAnimated:YES];
return NO;
}
- (void)displayPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier
{
NSString* name = (__bridge_transfer NSString*)ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSLog(name);
if (property == kABPersonPhoneProperty) {
ABMultiValueRef multiPhones = ABRecordCopyValue(person, kABPersonPhoneProperty);
for(CFIndex i = 0; i < ABMultiValueGetCount(multiPhones); i++) {
if(identifier == ABMultiValueGetIdentifierAtIndex (multiPhones, i)) {
CFStringRef phoneNumberRef = ABMultiValueCopyValueAtIndex(multiPhones, i);
CFRelease(multiPhones);
NSString *phoneNumber = (__bridge NSString *) phoneNumberRef;
CFRelease(phoneNumberRef);
self.txtTelNo.text = phoneNumber;
}
}
}
}
It feels like I am doing everything right and I have followed countless others and nothing seems to work. What could be the issue?