Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ranjeet

macrumors newbie
Original poster
Sep 21, 2010
6
0
i am totally new to this topic and searched on this but still very confused please help i need to get a phone number from user's address book based on the name user entered in a text field ....

please provide any tutorial based on this (if possible)
 
reply

i mean in an app. user types a name in textField and by clicking on find button if there is any entry matched to that name in user's contacts list then the corresponding numbers will be displayed in a label
 
This lets you search for a person by name. It will then load the person into a PersonView on whether or not they exist. You can specify what items you see or you can get just a specific property back. Don't forget that phone numbers a a multivalueref that will return a CFArray.

Code:
-(void)showPersonViewController
{
    // Fetch the address book 
    ABAddressBookRef addressBook = ABAddressBookCreate();
    // Search for the person named "Appleseed" in the address book
    NSArray *people = (NSArray *)ABAddressBookCopyPeopleWithName(addressBook, CFSTR("Appleseed"));
    // Display "Appleseed" information if found in the address book 
    if ((people != nil) && [people count])
    {
        ABRecordRef person = (ABRecordRef)[people objectAtIndex:0];
        ABPersonViewController *picker = [[[ABPersonViewController alloc] init] autorelease];
        picker.personViewDelegate = self;
        picker.displayedPerson = person;
        // Allow users to edit the person’s information
        picker.allowsEditing = YES;
        [self.navigationController pushViewController:picker animated:YES];
    }
    else 
    {
        // Show an alert if "Appleseed" is not in Contacts
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" 
                                                        message:@"Could not find Appleseed in the Contacts application" 
                                                       delegate:nil 
                                              cancelButtonTitle:@"Cancel" 
                                              otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
    
    [people release];
    CFRelease(addressBook);
}
 
thank you

This lets you search for a person by name. It will then load the person into a PersonView on whether or not they exist. You can specify what items you see or you can get just a specific property back. Don't forget that phone numbers a a multivalueref that will return a CFArray.

Code:
-(void)showPersonViewController
{
    // Fetch the address book 
    ABAddressBookRef addressBook = ABAddressBookCreate();
    // Search for the person named "Appleseed" in the address book
    NSArray *people = (NSArray *)ABAddressBookCopyPeopleWithName(addressBook, CFSTR("Appleseed"));
    // Display "Appleseed" information if found in the address book 
    if ((people != nil) && [people count])
    {
        ABRecordRef person = (ABRecordRef)[people objectAtIndex:0];
        ABPersonViewController *picker = [[[ABPersonViewController alloc] init] autorelease];
        picker.personViewDelegate = self;
        picker.displayedPerson = person;
        // Allow users to edit the person’s information
        picker.allowsEditing = YES;
        [self.navigationController pushViewController:picker animated:YES];
    }
    else 
    {
        // Show an alert if "Appleseed" is not in Contacts
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" 
                                                        message:@"Could not find Appleseed in the Contacts application" 
                                                       delegate:nil 
                                              cancelButtonTitle:@"Cancel" 
                                              otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
    
    [people release];
    CFRelease(addressBook);
}



thank you it really hel:)ped....
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.