I’m writing a custom addressbook app in ios and I use a singleton addressbookRef.
Here is my operation steps:
+ (ABAddressBookRef) sharedAddressBook
{
static ABAddressBookRef ref = nil;
if ( ref == nil )
{
ref = ABAddressBookCreate();
}
return ( ref );
}
step1:
Open my addressbook app
ABAddressBookRef addressBook = [ABAddressBook sharedAddressBook];
ABRecordRef person = ABAddressBookGetPersonWithRecordID( addressBook, 83 );
NSString* name= ABRecordCopyValue(person,kABPersonFirstNameProperty);
NSLog(@"%@",name);
console print “aaa”.
step2:
quit my app(enterBackground, not kill), change the “aaa” person name to “bbb” by using the system dialer.
step3:
open my app(enterForeground), do the same thing
ABAddressBookRef addressBook = [ABAddressBook sharedAddressBook];
ABRecordRef person = ABAddressBookGetPersonWithRecordID( addressBook, 83 );
NSString* name= ABRecordCopyValue(person,kABPersonFirstNameProperty);
NSLog(@"%@",name);
console print “aaa”.
My question is
1.Why the console print “aaa”, not “bbb” when used the old addressBookRef? When i change the [ABAddressBook sharedAddressBook] to ABAddressBookCreate(), everything seems to be ok. Why the old addressBookRef can not keep up-to-date?
2.Should I need do ABAddressBookCreate() at enterForeground everytime?
3.is the recordID changed when I edit the person info? I suspect.
Now I reloadAddressbook async when _ExternalChangeCallback! reloadAddressbook need reallocate all the person(wrapped) instances, but no need to recreate it’s cache data.