步驟
注冊廣播
let name1 = NSNotification.Name(rawValue:"NotFicationName")
NotificationCenter.default.addObserver(self, selector: #selector(ViewController.notfifica(sender:)), name: name1, object: nil)
注冊解析廣播的方法
@objc func notfifica(sender:NSNotification) {
print("接收廣播成功")
let dic = sender.userInfo
let va = dic?["key"]
print("\(va)")
}
發(fā)送廣播
let noT = NSNotification.Name(rawValue: "NotFicationName")
let dic = ["key":"value"]
NotificationCenter.default.post(name: noT, object: nil, userInfo:dic)