【问题标题】:Push Notification not received when app is in foreground ios flutter应用程序在前台时未收到推送通知
【发布时间】:2020-12-23 10:40:12
【问题描述】:

我已经为 Flutter 中的推送通知集成了 firebase。如果应用程序在前台,我会显示一个包含通知详细信息的对话框。我在android中正确接收通知。此外,iOS 通知在后台和设备锁定时工作正常。我也启用了推送通知和后台获取。有什么解决办法吗?有人遇到过这样的问题吗?

我正在使用这个 firebase 插件 https://pub.dev/packages/firebase_messaging

【问题讨论】:

    标签: android ios firebase flutter cross-platform


    【解决方案1】:
    1. 在 AppDelegate 中导入 UserNotifications。

    2. UNUserNotificationCenter.current().delegate = self in didFinishLaunch

    3. 在AppDelegate中实现下面的方法。

    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping(UNNotificationPresentationOptions) -> Void) { print("Push notification received in foreground.") completionHandler([.alert, .sound, .badge]) }

    【讨论】:

    • 正在接收通知。仅在应用运行时不接收
    • 是的,它会起作用,当应用程序在前台时显示通知,需要为 iOS 实现 UserNotification 框架
    • 谢谢。在哪里调用该方法 userNotificationCenter?
    • 收到通知,但几秒钟后它会从通知托盘中消失。如果有任何新通知,我会在其中显示一个对话框
    • 没有正确获取您的场景,如果您想显示警报,请编写代码以在打印语句下方显示对话框,它将起作用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-24
    • 2019-04-04
    • 2017-05-11
    • 2014-10-21
    • 1970-01-01
    相关资源
    最近更新 更多