Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 284
maignacio Avatar asked Sep 17 '12 08:09

maignacio


People also ask

Why are some of my iPhone contacts not deleted?

Above error message appears and prevents the certain contacts from being getting deleted. Any suggestion? If Contacts on iCloud, try this --> Restore contacts, calendars, bookmarks, and more using ... Else Add the email account that stores your contacts in the IOS mail app and enable Contacts.

How do I manage contacts on iPhone?

Go to Settings > Contacts > Accounts. Tap the account that has contacts that you want to add or remove. To add contacts, turn on Contacts. To remove contacts, turn off Contacts, then tap Delete from My iPhone.

How do I delete email contacts on IPAD?

Here's how to delete a contact: Open Contacts and tap the contact that you want to delete. Tap Edit. Scroll Down and tap Delete Contact then tap Delete Contact again to confirm.


2 Answers

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];

}
like image 123
andreacipriani Avatar answered Sep 21 '22 14:09

andreacipriani


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

like image 45
ChrisHaze Avatar answered Sep 18 '22 14:09

ChrisHaze