小编Mil*_*l3r的帖子

Flutter 应用程序的 Firebase 通知突然停止

我正在尝试将 FCM 集成到我的颤振应用程序中。我已经完成了 android 和 iOS 的所有连接设置。当我在云消息测试通知功能的帮助下发送通知时,通知在设备中正确接收。

我编写了一个函数脚本,它在给定时间自动发送通知。当我在大约 2 周前部署该功能时,它几乎按预期工作。大多数客户都收到了他们应该收到的通知。但是,过去几天通知已完全停止到达客户端。

我在 firebase 控制台中的功能登录表明通知已发送,但报告显示我的用户没有收到通知。

我确信我编写有效负载的方式有问题。

这是我的代码

exports.sendFollowerNotification = functions.database.ref('/notifications/{notificationID}')
.onCreate(async (snapshot, context) => {
  const notificationID = context.params.notificationID;
  const notificationData = snapshot.val();

  const getDeviceTokensPromise = admin.database()
    .ref('/DeviceTokens').orderByChild("subscribed").equalTo("1").once('value');


  //list all tokens in a array
  let tokensSnapshot;
  let tokens;

  const results = await Promise.all([getDeviceTokensPromise]);
  tokensSnapshot = results[0];
  if (!tokensSnapshot.hasChildren()) {
    return console.log('There are no notification tokens to send to.');
  }
  console.log('There are', tokensSnapshot.numChildren(), 'tokens to send notifications to.');

  tokens …
Run Code Online (Sandbox Code Playgroud)

push-notification firebase firebase-realtime-database flutter

5
推荐指数
1
解决办法
296
查看次数