Strange behaviour with iOS kABPersonModificationDateProperty, seems to update all the time

可紊 提交于 2020-01-13 03:57:23

问题


I'm seeing really weird behaviour in my iOS app using the ABAddressBook library. Wondering if anyone can give me some insight into whats happening in the background or if I have a logic error I just can't see.

Long story short I'm making a VOIP app that relies heavily on importing the user's contacts. I keep an online backup of these that are also used in conjunction with push notifications.

As they are modified on the phone I need to send an update request to the server to keep them accurate. The problem is many user devices are frequently spamming the server with very large blocks of contacts, at random intervals. One day it will be 50+ contacts, 5 mins later another 10, then it will be a month before a single one is updated. I have asked a few users that are friends and they can't recall modifying half of their address book over night.

My code is very simple, I store an NSDate every time I am required to send an update to the server, e.g. addition, modification or deletion. I know there is a callback that triggers when the address book has been updated, but this requires keeping a reference to the address book in memory at all times. I've done some testing and if the app crashes or the user kills the app, I loose any updates. Given its a background running VOIP app I feel it is possible people will kill it on an occasion to save battery or whatever. So for that reason I loop through all the contacts checking the kABPersonModificationDateProperty property against the last NSDate I have recorded. If the modified is newer I begin my update, like so.

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];

NSDate *lastChecked = [dateFormatter dateFromString:[PListData readStringFromFile:@"lastContactsArchive"]];


CFDateRef modifyDate = ABRecordCopyValue(ref, kABPersonModificationDateProperty);
...
...
else if ([(__bridge NSDate*)modifyDate compare:lastChecked]==NSOrderedDescending) // if modified after last check, create new contact and update
{
   ...
}

Is there something that I'm missing, is the modification date only updated when the name / phone numbers / email etc are changed ? Are they modified when iCloud syncs for example ? is a counter updated if they call the person on the phone ? etc.

I've tried debugging on 3 phones and all behave as I would expect. I'm really drawing a blank here and the server isn't happy with me so any help would be appreciated.


回答1:


Contacts may also update in background when iphone syncs contacts with iCloud / CardDav / Gmail / Exchange account.

Note that it also may happen while your app is running, so you should subscribe for address book updates.



来源:https://stackoverflow.com/questions/16715032/strange-behaviour-with-ios-kabpersonmodificationdateproperty-seems-to-update-al

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!