iOS kABPersonModificationDateProperty的奇怪行为似乎一直在更新 [英] Strange behaviour with iOS kABPersonModificationDateProperty, seems to update all the time

查看:101
本文介绍了iOS kABPersonModificationDateProperty的奇怪行为似乎一直在更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用ABAddressBook库的iOS应用程序中看到了非常奇怪的行为。想知道是否有人可以让我对背景中发生的事情有所了解,或者我是否有一个逻辑错误,我根本看不到。

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.

长话短说我正在制作一个VOIP应用程序,严重依赖于导入用户的联系人。我保留了这些的在线备份,这些备份也与推送通知一起使用。

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.

因为它们在手机上被修改我需要向服务器发送更新请求保持准确。问题是许多用户设备经常以随机的间隔向具有非常大的联系人块的服务器发送垃圾邮件。有一天它会有50多个联系人,5分钟后会再增加10个联系人,然后一个月就会更新一个联系人。我问过一些朋友,他们不记得过晚修改了一半的地址簿。

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.

我的代码非常简单,我存储了一个 NSDate 每当我需要向服务器发送更新时,例如添加,修改或删除。我知道有一个回调会在地址簿更新时触发,但这需要始终在内存中保留对地址簿的引用。我做了一些测试,如果应用程序崩溃或用户杀死应用程序,我将丢失任何更新。鉴于其背景运行VOIP应用程序,我觉得有可能人们会在节省电池或其他什么的时候杀死它。因此,我循环浏览所有联系人,检查 kABPersonModificationDateProperty 属性,对照我记录的最后一个 NSDate 。如果修改后更新,我会开始更新,就像这样。

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
{
   ...
}

我有什么东西吗?我失踪了,修改日期是否仅在更改名称/电话号码/电子邮件等时更新?例如,当iCloud同步时它们是否被修改?如果他们通过电话给这个人打电话,计数器会更新吗?

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.

我已尝试在3部手机上进行调试,所有操作都符合我的预期。我真的在这里画一个空白,服务器对我不满意所以任何帮助都会受到赞赏。

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.

推荐答案

当iphone与iCloud / CardDav / Gmail / Exchange帐户同步联系时,也可能在后台更新。

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.

这篇关于iOS kABPersonModificationDateProperty的奇怪行为似乎一直在更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆