3

I want to know if it's possible to extract a contact's Home Phone Number and Work Phone Number, instead of their Home FAX or Work FAX. If not, why is this a restriction?

The reference only mentions the following constants:

const ABPropertyID kABPersonPhoneProperty;  
const CFStringRef kABPersonPhoneMobileLabel;  
const CFStringRef kABPersonPhoneIPhoneLabel;  
const CFStringRef kABPersonPhoneMainLabel;  
const CFStringRef kABPersonPhoneHomeFAXLabel;  
const CFStringRef kABPersonPhoneWorkFAXLabel;  
const CFStringRef kABPersonPhoneOtherFAXLabel;  
const CFStringRef kABPersonPhonePagerLabel;

But if you use your iPhone, you'll notice there's many more labels than that (not to mention the custom ones). How can I pick them?

Berbare
  • 144
  • 1
  • 8
  • 1
    Take a [look here](http://stackoverflow.com/a/10275572/312312) – Lefteris Jan 09 '14 at 15:59
  • That helped a bit more. I still don't understand why we get a more direct way (const's above) for some phones but not for the Work or Home ones. Having to rely on a (non-mentioned in References) string comparation is weird, but it solved my problem, apparently. – Berbare Jan 10 '14 at 15:09

2 Answers2

1
//contactData is ABRecordRef
ABMultiValueRef phones = ABRecordCopyValue(contactData, kABPersonPhoneProperty);

for (CFIndex i=0; i < ABMultiValueGetCount(phones); i++) 
{
    NSString* phoneLabel = (NSString*) ABMultiValueCopyLabelAtIndex(phones, i);
    NSString* phoneNumber = (NSString*) ABMultiValueCopyValueAtIndex(phones, i);

    //for example
    if([phoneLabel isEqualToString:(NSString *)kABPersonPhoneMobileLabel])
    {
        //under phoneNumber you have a kABPersonPhoneMobileLabel value
    }
    .. add other standard labels
    else //custom label
    {

    }

    [phoneNumber release];
    [phoneLabel release];
}

CFRelease(phones);
Grzegorz Krukowski
  • 18,081
  • 5
  • 50
  • 71
1

kABHomeLabel and kABWorkLabel

if (CFStringCompare(phoneLabelRef, kABHomeLabel, 0) == kCFCompareEqualTo) {
        homePhone = (__bridge NSString *)phoneNumberRef;
} else if (CFStringCompare(phoneLabelRef, kABWorkLabel, 0) == kCFCompareEqualTo) {
        officePhone = (__bridge NSString *)phoneNumberRef;
}

See this excellent tutorial: http://www.appcoda.com/ios-programming-import-contact-address-book/

Jingshao Chen
  • 3,405
  • 2
  • 26
  • 34