maignacio
maignacio

Reputation: 183

iOS Address Book - How To Know Which Contact Was Added/Edited/Deleted?

My app needs to store a user's contacts on our servers (given the user's permission of course.) One of it's requirements is to reflect any changes on the devices address book (add/edit/delete) to the server.

Is there an easy way/best practice with regards to determining which address book contacts were changed prior to re-launching an application?

All I can see are callback methods to notify an application of a change in the address book, but it seems there are no documented ways to determine which contacts were added, edited, or deleted.

What I'm thinking of right now is to manually compare the new list of contacts with one stored on the device, then update both the application and the server of the changes. But I think that it might be too much if the user has a big amount of contacts.

Thanks!

Upvotes: 9

Views: 3029

Answers (2)

andreacipriani
andreacipriani

Reputation: 2591

You have to register your class with the ABAddressBookRegisterExternalChangeCallback passing an ABAddressBookRef and the callback ("addressBookDidChange" in my example)

ABAddressBookRef addressBook = //...

ABAddressBookRegisterExternalChangeCallback(addressBook, addressBookDidChange(__bridge_retained  void *)self);

void addressBookDidChange(ABAddressBookRef addressBook, CFDictionaryRef info, void  *context)
{
    //Something changed from last application launch, insert your logic here...

    //If you want to handle it in a "Objective-C" method you can do something like:
    [((__bridge ABManager*) context) yourObjectiveCMethod];

}

Upvotes: 2

ChrisHaze
ChrisHaze

Reputation: 2810

Look into using libsqlite3.dylib and creating a sql database that will access the flat files generated for all the properties needed and then compare your database to the users' devices periodically. Make sure both databases only acquire the bare necessities you will be needing from the abaddressbook framework.

Sample iOS project with sqlite3 library is here:

http://www.techotopia.com/index.php/An_Example_SQLite_based_iOS_7_Application

& Detail on doing so with ABAddressbook for contact's multi-value properties here:

http://linuxsleuthing.blogspot.com/2012/10/addressing-ios6-address-book-and-sqlite.html

Upvotes: 1

Related Questions