2010-12-14 2 views
2

큰 문제가 있습니다 ... 사용자 주소록과 주소를 다루는 앱을 작성할 계획입니다. 모든 것은 괜찮습니다 - 제가 addesse의 유형이 "직장", "집"또는 "기타"인지 여부를 결정할 수 없다는 사실을 제외하고는.주소록 FrameWork (iOS 4.2)에서 주소 유형을 결정하는 방법

집, 직장 및 기타 라벨을받는 방법을 아는 사람이 있습니까? 미리

감사

보리스

이되는 순간에 이용 함수 미안 :

+ (void)testing { 
//Get the addressbook 
ABAddressBookRef _addressBookRef = ABAddressBookCreate(); 

//Fetch all contacts 
NSArray* allPeople  = (NSArray *)ABAddressBookCopyArrayOfAllPeople(_addressBookRef); 

//Walk the contacts 
for (id record in allPeople) { 
    //Get the contact´s id 
    NSInteger recordId = ABRecordGetRecordID((ABRecordRef)record); 

    //Get the contact´s name and company 
    NSString* recordName = (NSString *)ABRecordCopyCompositeName((ABRecordRef)record); 
    NSString* recordCompany = (NSString *)ABRecordCopyValue((ABRecordRef)record, kABPersonOrganizationProperty); 

    //Get the contact´s addresses 
    CFTypeRef adressesReference = ABRecordCopyValue((ABRecordRef)record, kABPersonAddressProperty); 
    NSArray *adressesArray = (NSArray *)ABMultiValueCopyArrayOfAllValues(adressesReference); 
    CFRelease(adressesReference); 

    NSLog(@"ID: %d", recordId); 
    NSLog(@"Name: %@", recordName); 
    NSLog(@"Firma: %@", recordCompany); 

    for (NSString *adress in adressesArray) { 
    NSLog(@"Adresse: %@", adress); 
    } 

    [adressesArray release]; 
} 

CFRelease(_addressBookRef); 
[allPeople release]; 
NSLog(@"\n"); 
} 

와 로그 출력 here's :

ID : 1 이름 : 첫 번째 사용자 Firma : (null) 주소 : { 도시 = 로이 트 링겐 ; 국가 = 독일; CountryCode = de; Street = "일부 거리"; ZIP = 23456; }

주소 : { City = Reutlingen; 국가 = 독일; CountryCode = de; 상태 = BW; Street = "Street number 2"; ZIP = 98765; }

ID : 2 이름 : 두 번째 접촉 하기 Firma :하기 Firma 주소 : { 나라 = "미국"; CountryCode = us; Street = Test; 여기 }

답변

10

는 추출 된 주소록 값을 얻는 방법은 다음과 같습니다

ABMultiValueRef addresses = ABRecordCopyValue(ref, kABPersonAddressProperty); 
    for (CFIndex j = 0; j<ABMultiValueGetCount(addresses);j++){ 
     CFDictionaryRef dict = ABMultiValueCopyValueAtIndex(addresses, j); 
     CFStringRef typeTmp = ABMultiValueCopyLabelAtIndex(addreses, j); 
     CFStringRef labeltype = ABAddressBookCopyLocalizedLabel(typeTmp); 
     NSString *street = [(NSString *)CFDictionaryGetValue(dict, kABPersonAddressStreetKey) copy]; 
     NSString *city = [(NSString *)CFDictionaryGetValue(dict, kABPersonAddressCityKey) copy]; 
     NSString *state = [(NSString *)CFDictionaryGetValue(dict, kABPersonAddressStateKey) copy]; 
     NSString *zip = [(NSString *)CFDictionaryGetValue(dict, kABPersonAddressZIPKey) copy]; 
     NSString *country = [(NSString *)CFDictionaryGetValue(dict, kABPersonAddressCountryKey) copy]; 


     [street release]; 
     [city release]; 
     [state release]; 
     [zip release]; 
     [country release]; 
     CFRelease(dict); 
     CFRelease(type); 
     CFRelease(typeTmp); 
    } 
     CFRelease(addresses); 

라벨 유형이 당신을 위해 무엇을 찾고 있습니다.

행운 샤니

+0

안녕이 빠른 버전으로 변환 할 수 있습니까? – user998405

+0

나는 이것을 곧하려고 노력할 것이다. 감사 – shannoga