user857280
user857280

Reputation: 25

How to edit the existing contacts programmatically in iPhone

I want to edit the contact list programatically.is there any API's available for this.....

Upvotes: 1

Views: 2787

Answers (2)

Nikhil Dinesh
Nikhil Dinesh

Reputation: 3409

    -(void)showPersonViewController:(NSString *)nameInContact
{
    // Fetch the address book 
    ABAddressBookRef addressBook = ABAddressBookCreate();
    // Search for the person  in the address book
    NSArray *people = (NSArray *)ABAddressBookCopyPeopleWithName(addressBook, CFSTR(nameInContact));
    // Display the 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 the person is not in Contacts
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" 
                                                        message:[NSString stringWithFormat:@"Could not find %@ in the Contacts application", nameInContact] 
                                                       delegate:nil 
                                              cancelButtonTitle:@"Cancel" 
                                              otherButtonTitles:nil];
        [alert show];
        [alert release];
    }

    [people release];
    CFRelease(addressBook);
}

Upvotes: 1

Related Questions