let notificationName = Notification.Name.init("DownloadImageNotification")
NotificationCenter.default.post(name: notificationName, object: self,
userInfo: ["value1":"hangge.com", "value2" : 12345])
NotificationCenter.default.rx
.notification(Notification.Name.init("DownloadImageNotification"))
.takeUntil(self.rx.deallocated) //页面销毁自动移除通知监听
.subscribe(onNext: { notification in
//获取通知数据
let userInfo = notification.userInfo as! [String: AnyObject]
let value1 = userInfo["value1"] as! String
let value2 = userInfo["value2"] as! Int
print("获取到通知,用户数据是[\(value1),\(value2)]")
//等待3秒
sleep(3)
print(" 执行完毕")
}).disposed(by: disposeBag)
参考文章:Swift - RxSwift的使用详解63(通知NotificationCenter的使用)