3

我想知道是否可以提取联系人的家庭电话号码和工作电话号码,而不是他们的家庭传真或工作传真。如果不是,为什么这是一个限制?

该参考文献仅提及以下常量:

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

但是如果你使用你的 iPhone,你会发现标签比这多得多(更不用说自定义标签了)。我该如何挑选它们?

4

2 回答 2

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);
于 2014-01-09T13:33:17.870 回答
1

kABHomeLabelkABWorkLabel

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

看到这个优秀的教程: http: //www.appcoda.com/ios-programming-import-contact-address-book/

于 2015-04-08T13:17:00.977 回答