[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addressBookDidChange:) name:CNContactStoreDidChangeNotification object:nil];
-(void)addressBookDidChange:(NSNotification*)notification{
NSLog(@"change!!!");
}
我将CNContactStoreDidChangeNotification注册到NSNotificationCenter,但是当应用程序变为bg时,联系人有一些变化(例如添加新联系人(,并且应用程序变为激活,注册方法没有任何回调(没有日志"更改"(。
附言
但是当我添加方法
ABAddressBookRegisterExternalChangeCallback(ABAddressBookCreate(), addressBookChandedCallback, nil);
static void addressBookChandedCallback(ABAddressBookRef ab,
CFDictionaryRef info, void *context){`
NSLog(@"address change!!!");
}
日志:
地址更改!!
改变!!!
我相信问题出在你的代码上,而不是框架上。如果将其放在视图控制器中,则代码应如下所示:
-(void)viewWillAppear:(BOOL)animated {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addressBookDidChange:) name:CNContactStoreDidChangeNotification object:nil];
}
-(void)addressBookDidChange:(NSNotification*)notification
{
//Handle event here...
NSLog(@"change!!!");
}