2014-02-15 3 views
1

주소록에서 연락처의 집 전화 번호를 찾으려고합니다. 단지 그들을 읽고, 내가 어떤 말할 수 없다 - 모든iOS의 주소록에서 집 전화 번호를 알아내는 방법은 무엇입니까?

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

첫째, 이러한 상수의 이름이 이상하다 이렇게하려면, 나는 possible labels이 모두와 함께 전화 번호의 레이블을 비교하는거야 팩스가 아닌 집 전화 레이블. 글쎄, 나는 그 때 모든 것을 테스트하고 제거 과정을 사용해야 할 것이다.

NSString* phoneNumber = nil; 

// record is an ABRecordRef 
ABMultiValueRef phoneNumbers = ABRecordCopyValue(
    record, 
    kABPersonPhoneProperty 
); 

if (ABMultiValueGetCount(phoneNumbers) > 0) { 
    CFStringRef phoneLabelRef = ABMultiValueCopyLabelAtIndex(phoneNumbers, 0); 
    NSString* phoneLabel = (__bridge_transfer NSString*)phoneLabelRef; 

    NSLog(@"phone label: %@", phoneLabel); 
    NSLog(@"phone is mobile: %d", CFStringCompare(phoneLabelRef, kABPersonPhoneMobileLabel, 0) == kCFCompareEqualTo); 
    NSLog(@"phone is main: %d", CFStringCompare(phoneLabelRef, kABPersonPhoneMainLabel, 0) == kCFCompareEqualTo); 
    NSLog(@"phone is iPhone: %d", CFStringCompare(phoneLabelRef, kABPersonPhoneIPhoneLabel, 0) == kCFCompareEqualTo); 
    NSLog(@"phone is home fax: %d", CFStringCompare(phoneLabelRef, kABPersonPhoneHomeFAXLabel, 0) == kCFCompareEqualTo); 
    NSLog(@"phone is work fax: %d", CFStringCompare(phoneLabelRef, kABPersonPhoneWorkFAXLabel, 0) == kCFCompareEqualTo); 
    NSLog(@"phone is other fax: %d", CFStringCompare(phoneLabelRef, kABPersonPhoneOtherFAXLabel, 0) == kCFCompareEqualTo); 
    NSLog(@"phone is pager: %d", CFStringCompare(phoneLabelRef, kABPersonPhonePagerLabel, 0) == kCFCompareEqualTo); 
} 

다음은 시뮬레이터에서 미리로드 된 두 개의 연락처에 대한 인쇄물입니다. 모든 연락처 정보가 가짜이므로 걱정하지 마십시오.

phone label: _$!<Mobile>!$_ 
phone is mobile: 1 
phone is main: 0 
phone is iPhone: 0 
phone is home fax: 0 
phone is work fax: 0 
phone is other fax: 0 
phone is pager: 0 
FIRST = Kate, LAST = Bell, PHONE = (555) 564-8583, EMAIL = [email protected] 

케이트 벨에는 문제가 없습니다. 그녀의 휴대 전화가 모바일임을 감지 할 수 있습니다. 그러나 Anna Haro에는 문제가 있습니다. 라벨이 일치하지 않으므로 어떤 전화 번호 유형인지 알 수 없습니다.

phone label: _$!<Home>!$_ 
phone is mobile: 0 
phone is main: 0 
phone is iPhone: 0 
phone is home fax: 0 
phone is work fax: 0 
phone is other fax: 0 
phone is pager: 0 
FIRST = Anna, LAST = Haro, PHONE = 555-522-8243, EMAIL = [email protected] 

나는 정확한 값이 아이폰 OS의 미래 버전으로 변경할 수 있기 때문에 말 그대로 문자열 _%!<Home>!$_ 일치하지 않으려는 것입니다.

답변

2

일반 레이블 kABHomeLabel을 원합니다. 이것은 전화 번호, 전자 메일 및 주소에 사용되는 "집"레이블입니다.

관련 문제