NSNotification

2019-05-21  本文已影响0人  Alan龙马
//发送通知
NotificationCenter.default.post(name: NSNotification.Name(rawValue: kMJNewChatBadgeNotification), object: nil, userInfo: ["count": num])

//接收通知,记得要销毁通知
NotificationCenter.default.addObserver(self, selector: #selector(showNewBadgeNumber(_:)), name: NSNotification.Name(rawValue:kMJNewChatBadgeNotification), object: nil)

@objc func showNewBadgeNumber(_ sender: Notification?) {
    
    if let count = sender?.userInfo?["count"] as? Int{
        
    }
}
#pragma mark ************** 销毁通知
deinit {
    NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: kMJNewChatNotification), object: nil)
  
}
上一篇 下一篇

猜你喜欢

热点阅读