Qamar Suleiman
Qamar Suleiman

Reputation: 1226

Add Contacts into AddressBook without UI

Can anyone please provide me with a few lines of code i can use to add contacts into iphone without using the UI controls.There have been a few answers stating its simplicity but none has mentioned a few steps to do.Thanks

Upvotes: 1

Views: 906

Answers (2)

Nik Burns
Nik Burns

Reputation: 3423

this helper from Erica Sadun will come in very handy

https://github.com/erica/ABContactHelper

Upvotes: 1

Ole Begemann
Ole Begemann

Reputation: 135578

  1. Read the Address Book Programming Guide for iOS.
  2. Get a reference to the address book: ABAddressBookRef addressBook = ABAddressBookCreate();.
  3. Create a new person record: ABRecordRef person = ABPersonCreate();.
  4. Set the person's properties, e.g.: ABRecordSetValue(person, kABPersonFirstNameProperty, CFSTR("Katie"), &anError);.
  5. Add the record to the address book: ABAddressBookAddRecord().
  6. Save the changes: ABAddressBookSave().
  7. CFRelease(addressBook);.

Upvotes: 7

Related Questions