I have a strange problem where I register my iOS-app to listen to changes in the phones address book. The correct method is called when something changes in the address book but it gets called 2 - 6 times.
When the object gets created (singleton, so only one object), I register for notifications with this code:
ABAddressBookRegisterExternalChangeCallback(notificationAddressBook, addressBookChanged, (__bridge_retained void *)self);
The method that is called looks like this:
void addressBookChanged(ABAddressBookRef ab, CFDictionaryRef info, void *context){
ABAddressBookRevert(ab);
NSLog(@"ADDRESSBOOK CHANGED");
[phoneBookCopy updateCopy];
}
Any ideas how to solve this?
try this:
void addressBookChanged(ABAddressBookRef ab, CFDictionaryRef info, void *context){
ABAddressBookRevert(ab);
NSLog(@"ADDRESSBOOK CHANGED");
[phoneBookCopy updateCopy];
CFRelease(ab);
}
It was helped for me.
I had the same problem awhile ago, and I had to solve it by creating a NSTimer to handle the duplicate callbacks:
[self.changeTimer invalidate];
self.changeTimer = nil;
self.changeTimer = [NSTimer scheduledTimerWithTimeInterval:3.0
target:self
selector:@selector(handleAdressBookExternalCallbackBackground)
userInfo:nil
repeats:NO];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With