Priya
Priya

Reputation: 157

how can access existing contact number in my application

Hai how can we access existing contact number in our application? Please help me. Thank you

Upvotes: 0

Views: 285

Answers (2)

Sandeep Singh
Sandeep Singh

Reputation: 826

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; }

`

Upvotes: 1

Shrey
Shrey

Reputation: 1977

Check the ABAddressBook Reference

ABAdressBook Class Refernce

Upvotes: 1

Related Questions