Firestore推送通知“超时”错误通知并不总是被发送

我正在从我的应用程序调用一个函数,该函数向应用程序上的特定用户发送通知。大部分时间通知都会成功发送,但很多时候不会发送。当它没有被发送时,我检查日志以查看

函数执行耗时 60003 毫秒,完成状态为:'timeout'

我试过玩我的承诺/异步等待,但没有运气,因为我怀疑这就是问题所在。

这是我的云代码现在的样子

exports.sendNotification = functions.https.onRequest(async (request, response) => {

    if (request.method !== "POST") {
        response.status(400).send("Send it using post request");
        return;
    }

    var toUid = request.body.toUid
    var fcm = request.body.fcm
    var fromUid = request.body.fromUid
    var type = request.body.type
    var fromName = request.body.fromName
    var messageText = request.body.message

    if (toUid === "" || fromUid === "" || fcm === "") {
        response.status(400).send("Parameter is missing!");
        return;
    }

    // common data for both platforms
    const notification = {
     title: fromName,
     body: messageText,
    }
    const fcmToken = fcm

    // ios specific headers
    const apns = {
      headers: {
        "apns-collapse-id": 'toUid'
      },
      payload: {
        aps: {
          sound: 'default'
        },
        "data": {
          "fromUid": fromUid,
          "type": type
        }
      }
    }

    // final message
    const message = {
     token: fcmToken,
     notification: notification,
     apns: apns,
    }

    // send message
    try {
      return await admin.messaging().send(message);
      response.status(200).send("Done");
    } catch(e) {
      console.log('Error sending message:', e);
    }
});

我从应用程序调用函数如下

         AF.request("https://myproject.net/sendNotification", method: .post, parameters: parameters, encoding: JSONEncoding.default)
         .responseString { response in
             print(response)
            DispatchQueue.main.async {
                completion("done")
            }
         }

我已经看到其他类似问题的 stackoverflow 问题,其中建议使用 .post 和 JSONEncoding.default ,这就是我现在所拥有的。

以上是Firestore推送通知“超时”错误通知并不总是被发送的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>