2014-01-09 57 views
3

我想知道是否可以提取聯繫人的家庭電話號碼和工作電話號碼,而不是他們的本地傳真或工作傳真。如果沒有,爲什麼這是一個限制?ABPerson:如何獲取人的家庭電話和工作電話(不是傳真電話)

參考,只提到了以下常量:

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,你會發現有更多的標籤比(更不用提自定義的)。我如何挑選它們?

+1

乘坐[看這裏(http://stackoverflow.com/a/10275572/312312 ) – Lefteris

+0

這有助於更多。我仍然不明白爲什麼我們爲某些手機獲得更直接的方式(上面的const),但不能用於工作或家庭。不得不依賴(參考文獻中未提及的)字符串比較很奇怪,但它顯然解決了我的問題。 – Berbare

回答

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); 
+0

謝謝,但我已經有一個類似的代碼。我的問題是關於別的。 – Berbare

+0

嗯,你在問什麼比? :)對於自定義標籤,您只需具有「phoneLabel」不同的值。 –

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/