小编Sub*_*ury的帖子

Flutter 推送通知仅在应用程序处于后台时才有效

我的问题是关于使用 Flutter 和 firebase_messaging 插件的推送通知

问题:

我已将firebase_messaging插件集成到我的 Flutter 应用程序中以进行推送通知。我可以保证设置是正确的,因为我收到推送通知。仅当我的应用程序在后台运行时才收到推送(例如最小化但在系统内存中可用)时会出现问题。当应用程序在前台或被杀死时,不会收到推送。

为了提供我尝试过的解决方案,我无法弄清楚实际上需要做什么。

我遵循了有关此的教程并应用了每一步来克服该问题,但无济于事。

我正在使用 nodeJS 来处理 firebase-admin 和 serviceaccountkey 文件,因为我需要来自我的数据库的 device_tokens。

节点

 const firebase = require('firebase-admin');
 const serviceAccount = require('../controller/firebase/serviceAccountKey.json');
 firebase.initializeApp({
  credential: firebase.credential.cert(serviceAccount)
 });

 //Function to actually implement the push
 const pushNotificationInitiatorSubscription = (resultValue) => {
 let devicesTokenString = resultValue[0]['device_token'];
 const firebaseToken = devicesTokenString;
 const payLoad = {
   notification: {
   title: 'New Subscription',
   body: 'You have a new subscription to your material ' + resultValue[0]['course_name']
 }
};
const …
Run Code Online (Sandbox Code Playgroud)

push-notification node.js flutter firebase-cloud-messaging

7
推荐指数
1
解决办法
1万
查看次数