ABAddressBookRegisterExternalChangeCallback可以工作,但数据是陈旧的 [英] ABAddressBookRegisterExternalChangeCallback works, but data is stale

查看:115
本文介绍了ABAddressBookRegisterExternalChangeCallback可以工作,但数据是陈旧的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序注册回调一次:

My app registers the callback once:

notificationAddressBook = ABAddressBookCreate();

ABAddressBookRegisterExternalChangeCallback(notificationAddressBook, MyAddressBookExternalChangeCallback, self);

然后在我的回调中:

void MyAddressBookExternalChangeCallback (ABAddressBookRef notifyAddressBook,CFDictionaryRef info,void *context)
{
     NSLog(@"in MyAddressBook External Change Callback");

     ABAddressBookRevert(notifyAddressBook);         

     CFArrayRef peopleRefs = ABAddressBookCopyArrayOfAllPeopleInSource(notifyAddressBook, kABSourceTypeLocal);

     CFIndex count = CFArrayGetCount(peopleRefs);
     NSMutableArray* people = [NSMutableArray arrayWithCapacity:count];
     for (CFIndex i=0; i < count; i++) {
        ABRecordRef ref = CFArrayGetValueAtIndex(peopleRefs, i);
        ABRecordID id_ = ABRecordGetRecordID(ref);
        TiContactsPerson* person = [[[TiContactsPerson alloc] _initWithPageContext:[context executionContext] recordId:id_ module:context] autorelease];
        NSLog(@"name: %@", [person valueForKey:@"firstName"]);
        NSLog(@"phone: %@", [person valueForKey:@"phone"]);
        NSLog(@"modified: %@", [person valueForKey:@"modified"]);
        [people addObject:person];
     } 

     CFRelease(peopleRefs);
}

添加新联系人时,事件被触发正常,数据为第一个加法中的最新版本以及第二个和第三个加法中的最新版本。问题在于编辑现有联系人的详细信息。

When adding a new contact, the event is triggered fine, and the data is up-to-date in the first addition and the second and third. The problem is with editing an existing contact's details.

第一次触发事件时,数据对上次更新是正确的(我更改了一个联系人的电话号码) iPhone联系人),然后我切换到应用程序并获得最新的更新。然后我切换回地址簿,进行另一次更改,切换到我的应用程序并获得另一个事件。这次数据是陈旧的,最新的更改没有反映出来。

The first time the event is triggered the data is correct to the last update (I changed the phone number of one contact in the iPhone contacts), then I switch to the app and get the latest update. Then I switch back to the address book, make another change, switch to my app and get another event. This time the data is stale, the latest changes are not reflected.

我试图发布 ABAddressBookRef 实例并调用再次 ABAddressBookCreate()但它也没有帮助。

I tried releasing the ABAddressBookRef instance and call ABAddressBookCreate() again but it did not help either.

有什么想法吗?

推荐答案

尝试重新创建ABAddressBookRef。

Try to re-create ABAddressBookRef.

    void MyAddressBookExternalChangeCallback (ABAddressBookRef notifyAddressBook,CFDictionaryRef info,void *context)
    {
         NSLog(@"in MyAddressBook External Change Callback");

         //ABAddressBookRevert(notifyAddressBook);
         notifyAddressBook = ABAddressBookCreate();

         CFArrayRef peopleRefs = ABAddressBookCopyArrayOfAllPeopleInSource(notifyAddressBook, kABSourceTypeLocal);

         CFIndex count = CFArrayGetCount(peopleRefs);
         NSMutableArray* people = [NSMutableArray arrayWithCapacity:count];
         for (CFIndex i=0; i < count; i++) {
            ABRecordRef ref = CFArrayGetValueAtIndex(peopleRefs, i);
            ABRecordID id_ = ABRecordGetRecordID(ref);
            TiContactsPerson* person = [[[TiContactsPerson alloc] _initWithPageContext:[context executionContext] recordId:id_ module:context] autorelease];
            NSLog(@"name: %@", [person valueForKey:@"firstName"]);
            NSLog(@"phone: %@", [person valueForKey:@"phone"]);
            NSLog(@"modified: %@", [person valueForKey:@"modified"]);
            [people addObject:person];
         } 

         CFRelease(peopleRefs);    
    }

这篇关于ABAddressBookRegisterExternalChangeCallback可以工作,但数据是陈旧的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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