Created
March 17, 2012 07:02
-
-
Save Anil01/2055927 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ABAddressBookRef addressBook = ABAddressBookCreate(); // create address book record | |
ABRecordRef person = ABPersonCreate(); // create a person | |
NSString *phone = @"0123456789"; // the phone number to add | |
//Phone number is a list of phone number, so create a multivalue | |
ABMutableMultiValueRef phoneNumberMultiValue = | |
ABMultiValueCreateMutable(kABPersonPhoneProperty); | |
ABMultiValueAddValueAndLabel(phoneNumberMultiValue ,phone,kABPersonPhoneMobileLabel, NULL); | |
ABRecordSetValue(person, kABPersonFirstNameProperty, @"FirstName" , nil); // first name of the new person | |
ABRecordSetValue(person, kABPersonLastNameProperty, @"LastName", nil); // his last name | |
ABRecordSetValue(person, kABPersonPhoneProperty, phoneNumberMultiValue, &anError); // set the phone number property | |
ABAddressBookAddRecord(addressBook, person, nil); //add the new person to the record | |
ABRecordRef group = ABGroupCreate(); //create a group | |
ABRecordSetValue(group, kABGroupNameProperty,@"My Group", &error); // set group's name | |
ABGroupAddMember(group, person, &error); // add the person to the group | |
ABAddressBookAddRecord(addressBook, group, &error); // add the group | |
ABAddressBookSave(addressBook, nil); //save the record | |
CFRelease(person); // relase the ABRecordRef variable | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment