I am creating an application in which I used to update contacts from sqlite database on some rewrite actions. I used to fetch contacts from Addressbook of iPhone on user's permission everytime user logged in and insert it into database on Main thread.
I don't want to insert iphone contacts everytime to database when user login as it is exceeding logged in time and it is also not a good approach, if the Addressbook of iPhone is not modified so database insertion is happening on each loggin.
This is how I am fetching contacts
NSArray *thePeople = (__bridge NSArray *)ABAddressBookCopyArrayOfAllPeople(_addressBook);
NSMutableArray * _allPeoplesDictArr = [NSMutableArray array];
for (id person in thePeople)
{
ABMultiValueRef phones =(__bridge ABMultiValueRef)((__bridge NSString*)ABRecordCopyValue((__bridge ABRecordRef)(person), kABPersonPhoneProperty));
NSString* name = (__bridge NSString *)ABRecordCopyCompositeName((__bridge ABRecordRef)(person));
ABRecordRef record = (__bridge ABRecordRef)[thePeople objectAtIndex:loop];
if(ABRecordGetRecordType(record) == kABPersonType) // this check execute if it is person group
{
ABRecordID recordId = ABRecordGetRecordID(record); // get record id from address book record
recordIdString = [NSString stringWithFormat:@"%d",recordId]; // get record id string from record id
NSDate *modificationDate = (__bridge NSDate*) ABRecordCopyValue(record, kABPersonModificationDateProperty);
NSLog(@"modificationDate %@",modificationDate);
firstNameString = (__bridge NSString*)ABRecordCopyValue(record,kABPersonFirstNameProperty); // fetch contact first name from address book
lastNameString = (__bridge NSString*)ABRecordCopyValue(record,kABPersonLastNameProperty); // fetch contact last
NSLog(@"%@",firstNameString);
}
}
I am getting modification dates and can manage it in array but how will I know that Array is changed when I logged out or terminate the application.
There is another approach the I can match each and every contacts modification date from my insertion or creation date present in my sqlite database but still comparing will take time.
So isnt there any way to check MD5CheckSum or Addressbook on whole rather comparing each and every contacts creation date and insertion Date. And if Addressbook MD5CheckSum is modified so insertion or updation need to happens else dont.