2012-09-22 4 views
0

iPhone의 연락처에서 전화 번호를 가져 오려고합니다. 이 코드가이 방법에서 ABPeoplePickerNavigationControllerDelegate선택한 전화 번호 받기 [iPhone]

에서

-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier 

를 구현하고 그것을 작동 :

NSString *firstName = (NSString *)CFBridgingRelease(ABRecordCopyValue(person, kABPersonFirstNameProperty)); 
    NSLog(@"First Name ---> %@" ,firstName); 

    NSString *secondName = (NSString *)CFBridgingRelease(ABRecordCopyValue(person, kABPersonLastNameProperty)); 
    NSLog(@"Last name ---> %@" ,secondName); 

하지만 지금은도에서 선택한 전화 번호를 취할 필요 사용자. 나는이 함께 시도했지만 나를 위해 작동하지 않습니다

ABMultiValueRef 0xa36e990 with 1 value(s) 
    0: _$!<Mobile>!$_ (0xa36ee50) - (123) 456-7890 (0xa36ee70) 

그런 다음 나는이 함께 시도했지만이 작동하지 않습니다

NSString *numberSelected = (NSString *)CFBridgingRelease(ABRecordCopyValue(person, property)); 

이 나에게 이런 이상한 값을 제공 :

ABMutableMultiValueRef multi = ABRecordCopyValue(person, property); 
    CFStringRef phone = ABMultiValueCopyLabelAtIndex(multi, identifier); 
    NSLog(@"Number Selected ---> %@" ,(NSString *)CFBridgingRelease(phone)); 
    CFRelease(phone); 

    NSLog(@"Number Selected --> %@" ,numberSelected); 

표시되는 문자열이 아니라 :

_$!<Mobile>!$_ 

이제 무엇을해야할지 모르겠다 ... 나를 도울 수 있습니까?

감사합니다.

답변

1

함께 시도입니다 :

CFStringRef cfnumber; 
    ABMultiValueRef numbers = ABRecordCopyValue(person, kABPersonPhoneProperty); 
    for(CFIndex i = 0; i < ABMultiValueGetCount(numbers); i++) 
    { 
     if(identifier == ABMultiValueGetIdentifierAtIndex (numbers, i)) 
     { 
      //if tapped number identifier is the same as identifier number tapped 
      cfnumber = ABMultiValueCopyValueAtIndex(numbers, i); // copy the number to CFSTRING number 
     } 
    }   
    NSString *number = [NSString stringWithFormat:@"%@",cfnumber]; 
    CFRelease(cfnumber); 
+0

을하지만이 번호를 누를 때의 "속성"그 숫자입니다. 사용자가 연락처에 입력 한 모든 숫자는 필요하지 않지만 탭 한 번호 만 필요합니다. –

+0

수정 된 답변 확인 ... – Maulik

+0

완벽하게 작동합니다! 감사! –

관련 문제