iOS监听通讯录改变(应用每次打开都会收到被关闭期间的改变)

下个周要做关于通讯录这一块的一些应用,这块有一个非常重要的一点,通讯录变化之后重新上传通讯录到服务端.

  • 一般这么做
//监听通讯录变化
    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{
        // 比如上传
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容