Hai我们如何访问您申请中的现有联系电话?请帮我。 谢谢
答案 0 :(得分:1)
检查ABAddressBook参考
答案 1 :(得分:1)
您好在应用中添加地址簿框架工作。
然后在.h文件中添加ABPeoplePickerNavigationControllerDelegate
<。>文件中的
然后在添加按钮上执行此代码并跟随地址簿代理
-(void)ClkAddContactBtn:(id)sender
{
//创建选择器
ABPeoplePickerNavigationController * picker = [[ABPeoplePickerNavigationController alloc] init];
//将选择器的委托放置到controll
picker.peoplePickerDelegate = self;
// showing the picker
[self presentModalViewController:picker animated:YES];
// releasing
[picker release];
}
- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker
{ //将控制权分配给主控制器 [self dismissModalViewControllerAnimated:YES]; }
-(BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person
{
NSString *firstName=[[NSString alloc]init];
firstName=(NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSString *lastName=[[NSString alloc]init];
lastName=(NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);
if (lastName == nil)
{
lastName=@" ";
NSString *fullName=[[NSString alloc]init];
fullName=[NSString stringWithFormat:@" %@ %@", firstName, lastName];
txtContactName.text = fullName;
ABMultiValueRef multi = ABRecordCopyValue(person, kABPersonPhoneProperty);
txtContactNo.text = (NSString*)ABMultiValueCopyValueAtIndex(multi, 0);
// remove the controller
[self dismissModalViewControllerAnimated:YES];
}
else if(firstName == nil)
{
firstName=@" ";
NSString *fullName=[[NSString alloc]init];
fullName=[NSString stringWithFormat:@" %@ %@", firstName, lastName];
txtContactName.text = fullName;
ABMultiValueRef multi = ABRecordCopyValue(person, kABPersonPhoneProperty);
txtContactNo.text = (NSString*)ABMultiValueCopyValueAtIndex(multi, 0);
// remove the controller
[self dismissModalViewControllerAnimated:YES];
}
else
{
NSString *fullName=[[NSString alloc]init];
fullName=[NSString stringWithFormat:@" %@ %@", firstName, lastName];
txtContactName.text = fullName;
ABMultiValueRef multi = ABRecordCopyValue(person, kABPersonPhoneProperty);
txtContactNo.text = (NSString*)ABMultiValueCopyValueAtIndex(multi, 0);
// remove the controller
[self dismissModalViewControllerAnimated:YES];
}
return NO;
}
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier
{ 返回NO; }
`