You should add observer for change contact list notification like this:
(您应该为更改联系人列表通知添加观察者,如下所示:)
NotificationCenter.default.addObserver(self,selector: #selector(self.addressBookDidChange(_:)), name: NSNotification.Name.CNContactStoreDidChange,object: nil)
And then
(然后)
@objc func addressBookDidChange(_ notification: Notification){
print(notification.object as Any, notification.userInfo as Any)
//remove observer so far to prevent double method calling when making operations with contacts
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.CNContactStoreDidChange, object: nil)
//processing
//at some point return observer
NotificationCenter.default.addObserver(self,selector: #selector(ContactsListVC.addressBookDidChange(_:)), name: NSNotification.Name.CNContactStoreDidChange,object: nil)
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…