0

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.

user366584
  • 1,016
  • 1
  • 16
  • 34

1 Answers1

2

You are out of luck. If you terminate your application, there is zero public API to let you know there were changes. Going over all contacts will be necessary, as you have no other way to hear about changes.

Make sure to open a feature request at https://bugreport.apple.com, letting them know what API you need. Post the bug report number in the questio so people can duplicate the radar.

From the comments of another answer, here is a radar to duplicate: rdar://16154022 (thanks oski555)

Léo Natan
  • 56,823
  • 9
  • 150
  • 195