Cover by Vandad Nahavandipoor

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo

10.4. Inserting a Person Entry into the Address Book

Problem

You want to create a new person contact and insert it into the user’s address book.

Solution

Use the ABPersonCreate function to create a new person. Set the person’s properties using the ABRecordSetValue function and add the person to the address book using the ABAddressBookAddRecord function.

Discussion

After accessing the address book database using the ABAddressBookCreate function, you can start inserting new group and person records into the database. In this recipe, we will concentrate on inserting new person records. For information about inserting new groups into the address book, please refer to Recipe 10.5.

Use the ABPersonCreate function to create a new person record. Bear in mind that calling this function is not enough to add the person record to the address book. You must save the address book for your record to appear in the database.

By calling the ABPersonCreate function, you get a Core Foundation reference to a value of type ABRecordRef. Now you can call the ABRecordSetValue function to set the various properties of a new person entry. Once you are done, you must add the new person record to the database. You can do this using the ABAddressBookAddRecord function. After doing this, you must also save any unsaved changes to the address book database in order to truly preserve your new person record. Do this by using the ABAddressBookSave function.

So let’s combine all this into a method that allows us to insert ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required