2012-09-22 62 views
0

我正嘗試從iPhone上的聯繫人中獲取電話號碼。 我實現了拍下所選的電話號碼[iPhone]

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

在這種方法中

有這個代碼,它的工作原理:

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

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

,但現在我還需要考慮從選定的電話號碼用戶。我試圖與這一點,但它並沒有爲我工作:

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

這給我一個奇怪的值是這樣的:

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

然後我試圖與這也這並不工作:

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

它完美的作品!謝謝! –