Mac OS X 上未触发 CNContactStoreDidChangeNotification
CNContactStoreDidChangeNotification not fired on Mac OS X
我正在尝试观察 Contacts.app 等其他应用程序是否对联系人执行更新以更新我的应用程序中的联系人列表。该应用程序是 Mac OS X 应用程序。
我使用
在 AppDelegate.swift 中添加了观察者
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(AppDelegate.addressBookDidChange(_:)), name: CNContactStoreDidChangeNotification, object: nil)
选择器是
@objc func addressBookDidChange(notification:NSNotification){
print("Contacts need update!")
}.
尽管我使用 Contacts.app
更新联系人,但我没有观察到任何输出
我是不是漏掉了什么?
OS 是 macOS Sierra Beta 2。
我使用联系人框架。
要观察 CNContactStore
通知,您应该创建此商店并保留引用。
fileprivate var CNContactStore: CNContactStore? = nil
func addObserver() {
contactStore = CNContactStore()
NSNotificationCenter.default.addObserver(self, selector: #selector(addressBookDidChange(notification:)), name: NSNotification.Name.CNContactStoreDidChange, object: nil)
}
我正在尝试观察 Contacts.app 等其他应用程序是否对联系人执行更新以更新我的应用程序中的联系人列表。该应用程序是 Mac OS X 应用程序。
我使用
在 AppDelegate.swift 中添加了观察者 NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(AppDelegate.addressBookDidChange(_:)), name: CNContactStoreDidChangeNotification, object: nil)
选择器是
@objc func addressBookDidChange(notification:NSNotification){
print("Contacts need update!")
}.
尽管我使用 Contacts.app
更新联系人,但我没有观察到任何输出我是不是漏掉了什么?
OS 是 macOS Sierra Beta 2。 我使用联系人框架。
要观察 CNContactStore
通知,您应该创建此商店并保留引用。
fileprivate var CNContactStore: CNContactStore? = nil
func addObserver() {
contactStore = CNContactStore()
NSNotificationCenter.default.addObserver(self, selector: #selector(addressBookDidChange(notification:)), name: NSNotification.Name.CNContactStoreDidChange, object: nil)
}