CFErrorRef error = NULL;
ABAddressBookRef iPhoneAddressBook = ABAddressBookCreate();
ABRecordRef newPerson = ABPersonCreate();
ABRecordSetValue(newPerson, kABPersonFirstNameProperty,@"Davis", &error);
ABRecordSetValue(newPerson, kABPersonLastNameProperty, @"Scott", &error);
//Add my phone number
ABMutableMultiValueRef PhoneVar = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(PhoneVar,valueForKey:@"6176352360", kABPersonPhoneMainLabel, NULL);
ABRecordSetValue(newPerson, kABPersonPhoneProperty, PhoneVar,nil);
CFRelease(PhoneVar);
//Add my email address
ABMutableMultiValueRef EmailVar = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(EmailVar,@"d.scott@hotmail.com" , kABWorkLabel, NULL);
ABRecordSetValue(newPerson, kABPersonEmailProperty, EmailVar,nil);
CFRelease(EmailVar);
//Add my mailing address
ABMutableMultiValueRef Address = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);
NSMutableDictionary *addressDict = [[NSMutableDictionary alloc] init];
[addressDictionary setObject:streetString forKey:(NSString *) kABPersonAddressStreetKey];
[addressDictionary setObject:@"Boston" forKey:(NSString *)kABPersonAddressCityKey];
[addressDictionary setObject:@"02124" forKey:(NSString *)kABPersonAddressZIPKey];
[addressDictionary setObject:@"US" forKey:(NSString *)kABPersonAddressCountryKey];
ABMultiValueAddValueAndLabel(Address, addressDict, kABWorkLabel, NULL);
ABRecordSetValue(newPerson, kABPersonAddressProperty, Address,&error);
CFRelease(Address);
//Finally saving the contact in the address book
ABAddressBookAddRecord(iPhoneAddressBook, newPerson, &error);
ABAddressBookSave(iPhoneAddressBook, &error);
if (error != NULL)
{
NSLog(@"Saving contact failed.");
}
NSLog(@"Contact saved.");