如何在iPhone中以编程方式编辑现有联系人

时间:2011-07-29 06:33:22

标签: iphone contacts

我想以编程方式编辑联系人列表。有没有可用的API .....

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)