【问题标题】:Cloud Function not executed FlutterCloud Function 未执行 Flutter
【发布时间】:2021-05-02 05:51:02
【问题描述】:

我的 index.ts 中有这个云函数

import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
admin.initializeApp();

const db = admin.firestore();
const fcm = admin.messaging();

console.log("osakosak");
export const sendToDevice = functions.firestore
  .document('orders/{orderId}')
  .onCreate(async snapshot => {
    console.log("osakosak2");
    const order = snapshot.data();

    const querySnapshot = await db
      .collection('users')
      .doc(order.ustaID)
      .collection('tokens')
      .get();

    const tokens = querySnapshot.docs.map(snap => snap.id);

    const payload: admin.messaging.MessagingPayload = {
      notification: {
        title: 'New Order!',
        body: `you sold a ${order.day} for ${order.time}`,
        click_action: 'FLUTTER_NOTIFICATION_CLICK'
      }
    };

    return fcm.sendToDevice(tokens, payload);
  });

但是,当文档被添加时,不会发送通知。也没有打印任何东西。我已经部署了函数。

【问题讨论】:

  • 你检查过你的函数日志吗?
  • 你尝试过什么......!?

标签: firebase flutter google-cloud-firestore google-cloud-functions


【解决方案1】:

您需要检查 Firebase 函数中的函数错误日志。转到名为 sendToDevice 的函数,然后单击显示每日日志。还要确保集合和文档名称是正确的。我遇到了同样的问题,我通过检查日志并更正函数中的集合/文档名称来解决它们。

【讨论】:

    猜你喜欢
    • 2021-05-02
    • 2022-11-16
    • 1970-01-01
    • 2020-07-26
    • 2021-04-08
    • 1970-01-01
    • 2022-12-12
    • 2020-12-10
    • 2019-08-20
    相关资源
    最近更新 更多