开发者

How to edit the existing contacts programmatically in iPhone

开发者 https://www.devze.com 2023-03-23 13:57 出处:网络
I want to edit the contact list programatic开发者_Python百科ally.is there any API\'s available for this.....-(void)showPersonViewController:(NSString *)nameInContact

I want to edit the contact list programatic开发者_Python百科ally.is there any API's available for this.....


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


You can access the contacts programmatically and edit them using ABAddressBook.framework.

You can find documentation here:

http://developer.apple.com/library/mac/#documentation/userexperience/Reference/AddressBook/Classes/ABAddressBook_Class/Reference/Reference.html

and programming guide here:

http://developer.apple.com/library/ios/#documentation/ContactData/Conceptual/AddressBookProgrammingGuideforiPhone/Introduction.html

0

精彩评论

暂无评论...
验证码 换一张
取 消