Observing contact changes

1.1k Views Asked by At

Hi I have tried to observe the changes in the contacts list. In the View controller i set the notification for receive the event for contacts change.

class TestChangeContatct: UIViewController{

    @IBOutlet var textLabel: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()

        NotificationCenter.default.addObserver(
            self,
            selector: #selector(addressBookDidChange),
            name: NSNotification.Name.CNContactStoreDidChange,
            object: nil)
    }

    @objc func addressBookDidChange(notification: NSNotification){
        print("notification: \(notification)")
    }

}

But the addressBookDidChange is never called, anyone know why? From Apple:

Contacts Changed Notifications After a save is successfully executed, the contact store posts a CNContactStoreDidChange notification to the default notification center. If you cache any Contacts framework objects you need to refetch those objects, either by their identifiers, or with the predicates that were used to originally fetch them, and then release the cached objects. Note that cached objects are stale, but not invalid.

https://developer.apple.com/documentation/contacts

0

There are 0 best solutions below