下個周要做關于通訊錄這一塊的一些應用,這塊有一個非常重要的一點,通訊錄變化之后重新上傳通訊錄到服務端.
- 一般這么做
//監聽通訊錄變化
void addressBookChanged(ABAddressBookRef addressBook, CFDictionaryRef info, void *context)
{
// 比如上傳
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
ABAddressBookRef addresBook = ABAddressBookCreateWithOptions(NULL, NULL);
ABAddressBookRegisterExternalChangeCallback(addresBook, addressBookChanged, (__bridge void *)(self.viewcontrller));
}
順帶看看說明:
// Register an external change callback if you want to be informed of changes to the
// shared Address Book database by other instances or processes. The callback will be
// invoked by CFRunLoop on the thread where it was registered. The ABAddressBook does
// not take any action by default to flush or synchronize cached state with the database.
// If you want to ensure that you don't see any stale values, use ABAddressBookRevert().
// The info argument may eventually contain information describing the change. Currently
// it will always be NULL.
- iOS9以后引入新的聯系人框架,可以這樣用
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addressBookDidChange:) name:CNContactStoreDidChangeNotification object:nil];
-(void)addressBookDidChange:(NSNotification*)notification{
// 比如上傳
}