2011-01-10 29 views
6

Tôi cần nhận số điện thoại từ danh bạ.cách nhận số điện thoại của người được chọn trong danh bạ

Cho rằng mã của tôi là

- (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; 
} 

đây nó sẽ hiển thị trong giao diện điều khiển như thế này

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

Đây (929) 230-8622 là số điện thoại di động, Làm thế nào tôi có thể có được chỉ số điện thoại di động.

Sau khi chọn liên hệ, tôi cần đóng bộ điều khiển chế độ xem này.

Đối với điều đó tôi viết mã như thế này

[self dissmissModalViewControllerAnimated: YES];

Nhưng nó cho thấy waning rằng myclass có thể không đáp ứng dissmissModalViewController.

Làm cách nào tôi có thể thực hiện điều đó sau khi lựa chọn tôi cần đóng bộ điều khiển chế độ xem này.

ai cũng có thể giúp tôi.

Cảm ơn bạn trước.

Trả lời

4

tôi giải quyết vấn đề của tôi sử dụng bằng cách thêm mã này.

- (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; 
} 

Hy vọng người hữu ích này gặp vấn đề như tôi.

+0

Điều này hoạt động rất lạ trong một số trường hợp ... Trong trường hợp liên hệ có hai số mà phonenumberselected là số di động nếu bạn chọn số nhà, và nó trả về null nếu bạn chọn số điện thoại di động ... Bất kỳ ý tưởng vấn đề là gì !? Tôi đã sử dụng chính xác mã giống như bạn ... – simonthumper

2

ghi bên dưới mã trong bạn

-(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

biến số chỉ là để biết số điện thoại mà bạn có cho số liên lạc cụ thể – dks1725

+0

Đây có phải là công việc trong iphone 3.0 – MaheshBabu

Các vấn đề liên quan