我有一个能够接收推送通知的应用程序。
当应用程序处于后台模式时,推送通知显示良好,但如果应用程序处于前台模式,我想显示我的自定义 View
包含来自 userInfo
的信息。
如何从我的 appDelegate didReceiveRemoteNotification
通知任何 viewController
以显示此自定义 View 并向那里发送 userInfo
字典?
有人可以帮我解决我的问题吗?
最佳答案
您可以发送通知,然后您想要收到警报的 viewController 可以拥有它们的观察者:
NSNotificationCenter.defaultCenter().postNotificationName("nameOfNotification", object: yourVariableContainingUserInfo)
你能像这样添加观察者吗:
NSNotificationCenter.defaultCenter().addObserver(self, selector: "nameOfNotification:", name: "nameOfNotification", object: nil)
你的选择器看起来像这样:
func nameOfNotification(notification: NSNotification) {
if let dict = notification.object as? NSDictionary {
//user your userInfo dictionary here
}
}
关于ios - 在前台推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33303349/