我正在使用ABAddressBookRegisterExternalChangeCallback
在ios地址簿联系人更改时收到通知。
如何从回调中获取更新(添加/删除/修改)的联系人列表?我不想再次重新加载我的整个联系人列表。
我似乎无法在文档中的任何位置找到它。任何人都可以指导我,怎么做?
答案 0 :(得分:3)
你做不到。您可以做的是这将为您提供“在给定时间内修改”的联系人列表,例如:
void MyAddressBookExternalChangeCallback (ABAddressBookRef notifyAddressBook,CFDictionaryRef info,void *context)
{
//The addressbook object get's updated.
CFArrayRef peopleRefs = ABAddressBookCopyArrayOfAllPeopleInSource(notifyAddressBook, kABSourceTypeLocal);
ABAddressBookRevert(notifyAddressBook);
CFIndex count = CFArrayGetCount(peopleRefs);
for (CFIndex i=0; i < count; i++) {
ABRecordRef ref = CFArrayGetValueAtIndex(peopleRefs, i);
NSDate* datemod = (__bridge_transfer NSDate *)(ABRecordCopyValue(ref, kABPersonModificationDateProperty));
NSTimeInterval distanceBetweenDates = [[NSDate date] timeIntervalSinceDate:datemod];
int seconds = round(distanceBetweenDates);
if(seconds < 60){
ABCPerson * person = [[ABCFacade sharedABCFacade] convertABRecordRef:ref];
NSLog(@"modifactiondate: %@", [person modificationdate]);
[[ABCFacade sharedABCFacade] replacePersonInPersonListWithPerson:person];
}
}
NSLog(@"Yes it does get called by this change %@", context);
[[ABCFacade sharedABCFacade] ABRefresh];
}