【问题标题】:push notification in foreground在前台推送通知
【发布时间】:2016-01-23 01:11:28
【问题描述】:

我有一个能够接收推送通知的应用程序。

当应用程序处于 background 模式时,推送通知显示良好,但如果应用程序处于 foreground 模式,我想显示我的 custom view 以及来自 @987654323 的信息@。

如何从我的 appDelegate didReceiveRemoteNotification 通知任何 viewController 以显示此自定义视图并将 userInfo 字典发送到那里?

有人可以帮我解决我的问题吗?

【问题讨论】:

标签: ios swift push-notification foreground


【解决方案1】:

你可以发送一个通知,然后你想要被提醒的 viewControllers 可以有他们的观察者:

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
    }
}

【讨论】:

    【解决方案2】:

    您可以使用 NSNotificationCenterdidReceiveRemoteNotification 通知您的 viewcotroller。然后,您可以使用 NSNotificationCenter 方法中传递的 userinfo 字典根据需要显示自定义视图。

    【讨论】:

      猜你喜欢
      • 2019-02-07
      • 2019-06-26
      • 2019-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-25
      • 2021-11-27
      • 2020-06-14
      相关资源
      最近更新 更多