Hai how can we access exi开发者_如何学编程sting contact number in our application? Please help me. Thank you
Hello Add Addressbook frame work in your app.
Then add ABPeoplePickerNavigationControllerDelegate in .h file
in .m file
then on add button perform this code`and following address book delegates
-(void)ClkAddContactBtn:(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];
}
- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker
{ // assigning control back to the main controller [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
{ return NO; }
`
Check the ABAddressBook Reference
ABAdressBook Class Refernce
精彩评论