0
我想在ABPeoplePickerView中添加新記錄,並希望檢索添加的記錄,所以請任何機構都有想法。如何在ABPeoplePickerView中添加新記錄?
我想在ABPeoplePickerView中添加新記錄,並希望檢索添加的記錄,所以請任何機構都有想法。如何在ABPeoplePickerView中添加新記錄?
CFErrorRef error = NULL;
ABAddressBookRef iPhoneAddressBook = ABAddressBookCreate();
ABRecordRef newPerson = ABPersonCreate();
ABMutableMultiValueRef phoneNumberMultiValue = ABMultiValueCreateMutable(kABPersonPhoneProperty);
ABMultiValueAddValueAndLabel(phoneNumberMultiValue, StrPhno, kABHomeLabel, NULL);
ABRecordSetValue(newPerson, kABPersonFirstNameProperty, StrAdress, &error);
ABRecordSetValue(newPerson, kABPersonPhoneProperty, phoneNumberMultiValue, nil);
ABAddressBookAddRecord(iPhoneAddressBook, newPerson, &error);
ABAddressBookSave(iPhoneAddressBook, &error);
if (error != NULL)
{
NSLog(@"Danger Will Robinson! Danger!");
}
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
// Display only a person's phone, email, and birthdate
NSArray *displayedItems = [NSArray arrayWithObjects:[NSNumber numberWithInt:kABPersonPhoneProperty],
[NSNumber numberWithInt:kABPersonEmailProperty],
[NSNumber numberWithInt:kABPersonBirthdayProperty], nil];
picker.displayedProperties = displayedItems;
// Show the picker
[self presentModalViewController:picker animated:YES];
[picker release];