Reputation: 701
I started developing a settings page for my app.
On this page, the user can tap a "+" button which will open the ABPeoplePickerNavigationController
. When the contact is tapped, the text fields on the settings page will be filled appropriately with the correct data from the chosen user.
I understand that if I want to retrieve someone's work email, it's:
NSString *workEmail = (__bridge NSString *)ABMultiValueCopyValueAtIndex(emails, 1);
and for home it would be:
NSString *homeEmail = (__bridge NSString *)ABMultiValueCopyValueAtIndex(emails, 0);
But as far as retrieving different types of phone numbers, I am stuck.
I would appreciate it much if someone could tell me how to get the different types of phone numbers hopefully similar to the way I get the two emails.
Upvotes: 2
Views: 2231
Reputation: 43472
Well, first off, you understand wrong--there's no guarantee that the user's home email address is #0. What if you only have that user's work email? Then that will be in slot 0.
What you want is ABMultiValueCopyLabelAtIndex()
, which when used with named constants will tell you which is which:
ABPersonRef person = ...;
ABMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonPhoneProperty);
if (phoneNumbers) {
CFIndex numberOfPhoneNumbers = ABMultiValueGetCount(phoneNumbers);
for (CFIndex i = 0; i < numberOfPhoneNumbers; i++) {
CFStringRef label = ABMultiValueCopyLabelAtIndex(phoneNumbers, i);
if (label) {
if (CFEqual(label, kABWorkLabel)) {
/* it's the user's work phone */
} else if (CFEqual(label, kABHomeLabel)) {
/* it's the user's home phone */
} else if (...) {
/* other specific cases of your choosing... */
} else {
/* it's some other label, such as a custom label */
}
CFRelease(label);
}
}
CFRelease(phoneNumbers);
}
Upvotes: 7