Iphone 如何从手机通讯簿中选择特定号码?
如何从手机通讯簿中选择特定号码 我从通讯簿中获得了一个联系人,但只检索到了手机号码。我应该怎么做才能让用户选择手机/家庭/其他号码 这是我的密码:Iphone 如何从手机通讯簿中选择特定号码?,iphone,objective-c,addressbook,Iphone,Objective C,Addressbook,如何从手机通讯簿中选择特定号码 我从通讯簿中获得了一个联系人,但只检索到了手机号码。我应该怎么做才能让用户选择手机/家庭/其他号码 这是我的密码: -(IBAction)pickContact { // creating the picker ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init]; // place the delegat
-(IBAction)pickContact
{
// creating the picker
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
// place the delegate of the picker to the controll
picker.peoplePickerDelegate = self;
// showing the picker
[self presentModalViewController:picker animated:YES];
// releasing
[picker release];
}
-(void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker {
// assigning control back to the main controller
[self dismissModalViewControllerAnimated:YES];
}
-(BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person {
Contact *cont=[[Contact alloc] init];
// setting the first name
cont.fName = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
// setting the last name
cont.lastName = (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);
// setting the number
/*
this function will set the first number it finds
if you do not set a number for a contact it will probably
crash
*/
//ABMultiValueRef multi = ABRecordCopyValue(person, kABPersonPhoneProperty);
// cont.number = (NSString*)ABMultiValueCopyValueAtIndex(multi, 0);
ABMultiValueRef phones =(NSString*)ABRecordCopyValue(
person, kABPersonPhoneProperty);
CFIndex numPhoneNums = ABMultiValueGetCount(phones);
if(numPhoneNums == 0) {
NSLog(@"No number available");
cont.number = @"No number available";
} else {
cont.number = (NSString*) ABMultiValueCopyValueAtIndex(phones, 0);
}
…其余的工作正常。要获取所有类型的电话号码…person是ABRecordRef的一个实例
NSMutableArray *arPhList = [[NSMutableArray alloc] init];
ABMultiValueRef phones = ABRecordCopyValue(person, kABPersonPhoneProperty);
for(CFIndex j = 0; j < ABMultiValueGetCount(phones); j++)
{
CFStringRef phoneNumberRef = ABMultiValueCopyValueAtIndex(phones, j);
NSString *phoneLabel =(NSString*) ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(phones, j));
NSString *phoneNumber = (NSString *)phoneNumberRef;
NSDictionary *dicTemp = [[NSDictionary alloc]initWithObjectsAndKeys:phoneNumber,@"value", phoneLabel,@"label", nil];
[arPhList addObject:dicTemp];
}
手机上有所有的手机号码、家庭电话号码、传真号码等
但您只使用索引0
您只使用第一个电话号码。它不会是移动的
用于循环numphoneums以访问所有数字
else {
cont.number = (NSString*) ABMultiValueCopyValueAtIndex(phones, **0**);
}