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!
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.
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.
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.
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];
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With