I found a tutorial online that extends that Apple QuickStart Application which is the basic Address Book Application and another that returns the first phone number regardless of what phone number was clicked. I want to display only the selected phone number in the label. The label is called phoneNumber:
- (BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person
property:(ABPropertyID)property
identifier:(ABMultiValueIdentifier)identifier{
ABMutableMultiValueRef phoneMulti = ABRecordCopyValue(person, kABPersonPhoneProperty);
NSMutableArray *phones = [[NSMutableArray alloc] init];
int i;
for (i = 0; i < ABMultiValueGetCount(phoneMulti); i++) {
NSString *aPhone = [(NSString*)ABMultiValueCopyValueAtIndex(phoneMulti, i)autorelease];
[phones addObject:aPhone];
}
NSString *mobileNo = [phones objectAtIndex:0];
self.phoneNumber.text = phones;
[self dismissModalViewControllerAnimated:YES];
return NO;
}
How do I ensure that the label is the one selected by the user and not just the first array entry(or any other array entry i code in)
Thanks
I'm not sure I understand your question, but if you're trying to get the phone number and/or label your user actually selected, you can use this:
- (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier {
// ensure user picked a phone property
if (property == kABPersonPhoneProperty) {
ABMultiValueRef phone = ABRecordCopyValue(person, property);
CFStringRef selectedNumber = ABMultiValueCopyLabelAtIndex(phone, identifier);
CFStringRef selectedLabel = ABMultiValueCopyValueAtIndex(phone, identifier);
// insert code to do something with the values above
[self dismissModalViewControllerAnimated:YES];
return NO; } // end if
else {
// display an alert or something - handle the error
} } // end else, end method
I'm not following your code snippet - not sure what you're using the array for if all you want is the user's selected choice.