【问题标题】:Firebase push notifications not working in the background when sent from a REST API从 REST API 发送时,Firebase 推送通知在后台不起作用
【发布时间】:2021-02-28 19:05:02
【问题描述】:

我需要有关 Flutter 通知的帮助。 我已经在我的颤振应用程序中配置了 firebase_messaging。当我从 Firebase 控制台发送测试通知时,它们在前台和后台工作。当我从后端 rest api 服务发送通知时,它们仅在前台工作。即在这种情况下仅触发 onMessage

来自 REST API 的示例通知正文:

{notification: {title: null, body: null}, data: {intent: payment, body: 2500 shillings payment made, title: You have paid, click_action: FLUTTER_NOTIFICATION_CLICK}}

【问题讨论】:

    标签: flutter firebase-cloud-messaging flutter-notification


    【解决方案1】:

    您应该在通知负载中添加"content_available":true。 试试这个载荷来发送通知。

    { 
    "to": "your title name", 
    "content_available": true,
     "notification": {
     "title": "TITLE TEXT", 
    "body": "BODY TEXT",
     "content_available": true
     },
     "data": { 
    "body": "BODY TEXT",
     "title": "TITLE TEXT", 
    "click_action": "FLUTTER_NOTIFICATION_CLICK"
     }
     }
    

    【讨论】:

    • 谢谢你。我的问题是在通知中为标题和正文提供空值。 {通知:{标题:null,正文:null,},数据:{意图:付款,正文:“BODY TEXT”,标题:“TITLE TEXT”,click_action:FLUTTER_NOTIFICATION_CLICK}}
    • 如果有帮助,则将其设置为接受答案(蓝色勾号)this。
    猜你喜欢
    • 1970-01-01
    • 2017-10-29
    • 1970-01-01
    • 2021-05-02
    • 2018-12-31
    • 2017-04-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多