Add entry to contacts using iPhone SDK

So i recently started programming for iPhone. As part of the project i’m currently working on, i have to add new entries to the phones address book (contacts). The address book api is not very intuitive, seems to be a straight C api and is poorly documented. It took me a lot of googling to find the solution, so i promissed my self i would post the code once i found it .

I finally found what i was looking for over at the forum ( – post nr. 35 by MediadorAv – code below is a straight copy, with english naming).

This is what the code looks like:

ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef person = ABPersonCreate();

ABRecordSetValue(person, kABPersonFirstNameProperty, @"Kate" , nil);
ABRecordSetValue(person, kABPersonLastNameProperty, @"Hutson", nil);
ABAddressBookAddRecord(addressBook, person, nil);
ABAddressBookSave(addressBook, nil);


Code should be pretty self explanatory. To get it running, you need to add the AddressBook framework to your project, and import AddressBook/ABAddressBook.h and AddressBook/ABPerson.h. For more property constants, have a look at ABPerson.h.

Tags: , , , , , , , ,

7 Responses to “Add entry to contacts using iPhone SDK”

  1. Brainwash Inc. » Blog Archive » iPhone: add contacts to the address book Says:

    […] From: Add entry to contacts using iPhone SDK « Mr. Rask […]

  2. James Sun Says:

    Olav –

    The sample code you posted worked great! Thanks!


  3. Sumangala Says:

    Thanks alot for this code… It works out… 🙂

  4. Hudson Says:

    This post is just to add a single-value contact. To add a multi-value contact is very different. Do you how?
    Send me an email.

  5. SAURABH Says:

    Thanx.. It worked gr8.. Can you also help by providing code for saving all details like phone no , email etc .


  6. Sandy Says:


    It possible to create a contact under a group.. using iPhone SDK?

  7. Ondrej Says:


    Thanks for the great snippet, it showed me the right direction. Anyway, I just finished a full example that allows you to add phone numbers, emails, address, urls and other stuff … so if you want to check it out:

    Cheers, great stuff,

    Ondrej 🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: