问题描述
|
我正在开发一个应用程序,必须打开通讯录,我使用ABPeoplePickerNavigationController打开通讯录,并已为所有用户存储了电话号码和电子邮件,但是我不知道如何存储电话号码或电子邮件的值,假设如果用户单击电子邮件字段,则电子邮件地址存储在某个变量中,而如果单击电话号码存储在另一个变量中。
解决方法
您好,请在下面找到代码...
您可以从iPhone通讯录中获取FirstName,LastName,人物图像和MobileNumber
将Button添加到ViewController并将此代码添加到您的button click事件。
-(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;
}