2011-01-10 56 views
6

我需要從聯繫人中獲取電話號碼。如何獲取聯繫人中選定人員的電話號碼

對於我的代碼是

- (IBAction)contacts { 

    NSLog(@"contacts clicked "); 

    ABPeoplePickerNavigationController *peoplePickerController = [[ABPeoplePickerNavigationController alloc] init]; 
    peoplePickerController.peoplePickerDelegate = self; 
    [self presentModalViewController:peoplePickerController animated:NO]; 
    [peoplePickerController release]; 

} 
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker 
     shouldContinueAfterSelectingPerson:(ABRecordRef)person { 
    NSString *number = (NSString *)ABRecordCopyValue(person, kABPersonPhoneProperty); 

    NSLog(@" %@",number); 
    return YES; 
} 

這顯示在控制檯這樣

ABMultiValueRef 0x740b680 with 1 value(s) 
    0: _$!<Mobile>!$_ (0x7419880) - (929) 230-8622 (0x740b490) 

這裏(929) 230-8622是手機號碼,我怎麼能得到的只有手機號碼。

選擇聯繫後,我需要關閉此視圖控制器。

對於我寫這樣

代碼[自dissmissModalViewControllerAnimated:YES];

但它表明,myclass可能不會響應dissmissModalViewController。

我該怎麼做,選擇後我需要關閉這個視圖控制器。

任何人都可以幫助我。

謝謝你提前。

回答

4

我使用添加了此代碼解決我的問題。

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker 
     shouldContinueAfterSelectingPerson:(ABRecordRef)person 
           property:(ABPropertyID)property 
           identifier:(ABMultiValueIdentifier)identifier { 
    if (property == kABPersonPhoneProperty) { 
     ABMultiValueRef emails = ABRecordCopyValue(person, property); 
     CFStringRef phonenumberselected = ABMultiValueCopyValueAtIndex(emails, identifier); 
     CFStringRef emailLabelSelected = ABMultiValueCopyLabelAtIndex(emails, identifier); 
     CFStringRef emailLabelSelectedLocalized = ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(emails, identifier)); 
     NSLog(@"\n EmailValueSelected = %@ \n EmailLabelSelected = %@ \n \EmailLabeSelectedlLocalized = %@", phonenumberselected, emailLabelSelected, emailLabelSelectedLocalized); 

     NSString *aNSString = (NSString *)phonenumberselected; 



     [ self dismissModalViewControllerAnimated:YES ]; 
     return NO; 
    } 
    return YES; 
} 

希望這有助於誰面對像我這樣的問題。

2

寫下面的代碼在你的

-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person 

{  

    ABMultiValueRef mul; 
    mul=(NSString *) ABRecordCopyValue(person, kABPersonEmailProperty); 
    int count= ABMultiValueGetCount(mul); 
    NSString *name=(NSString *) ABMultiValueCopyValueAtIndex(mul,0); 

} 
+0

計數變量只是知道有多少個手機號,你有特定的聯繫 – dks1725 2011-01-11 04:22:02

+0

是在iPhone 3.0 – MaheshBabu 2011-01-12 06:24:00

相關問題