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 macrumors.com forum (http://forums.macrumors.com/showthread.php?t=449981&page=2 – 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);
CFRelease(person);
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: ABAddressBook, ABPerson, Add to contacts, Address book, API, Contacts, iPhone, iPhone SDK, SDK
March 27, 2009 at 8:06 pm |
[...] From: Add entry to contacts using iPhone SDK « Mr. Rask [...]
September 21, 2009 at 12:24 am |
Olav -
The sample code you posted worked great! Thanks!
James