我正在开发一个应用程序,并且我必须打开地址簿,我已经使用ABPeoplePickerNavigationController打开地址簿,并且已经为所有用户存储了电话号码和电子邮件,但是我不知道如何存储电话号码或电子邮件的价值,假设用户点击电子邮件字段,电子邮件地址存储在某个变量中,如果点击电话号码存储在另一个变量中。
答案 0 :(得分:2)
您好请找到以下代码......
您可以从iPhone地址簿中获取FirstName,LastName,此图像和MobileNumber
向ViewController添加按钮,并将此代码添加到按钮点击事件中。
-(IBAction)btnGetNameClicked:(id)sender {
// 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];
}
-(BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person {
// setting the first name
lblFirstName.text = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
// setting the last name
lblLastName.text = (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);
ABMultiValueRef multi = ABRecordCopyValue(person, kABPersonPhoneProperty);
lblNumber.text = (NSString*)ABMultiValueCopyValueAtIndex(multi, 0);
if(ABPersonHasImageData(person)){
imgPerson.image = [UIImage imageWithData:(NSData *)ABPersonCopyImageData(person)];
} else {
imgPerson.image = [UIImage imageNamed:@"NotAvailable.png"];
}
// remove the controller
[self dismissModalViewControllerAnimated:YES];
return NO;
}