FCM通知不会在我的ios设备上显示

时间:2019-09-14 06:48:07

标签: node.js firebase google-cloud-firestore firebase-cloud-messaging google-cloud-functions

从FCM消息获取推送通知时,我一直遇到很多问题。 我使用了文档来尝试通过云功能实现这一点,但是它不起作用。

我正在使用Google Firestore。

const functions = require("firebase-functions");
// The Firebase Admin SDK to access the Firebase Realtime Database.

const admin = require("firebase-admin");
admin.initializeApp();

// // Create and Deploy Your First Cloud Functions
// // https://firebase.google.com/docs/functions/write-firebase-functions
//

exports.helloWorld = functions.https.onRequest((request, response) => {
  response.send("Hello from Hanisa!");
});

exports.sendPushNotifications = functions.https.onRequest((req, res) => {
  res.send("Attempting to send push notification...");
  console.log("LOGGER --- Trying to send push message...");

  var uid = "GfIebNhpO8falK7wyt0ksB8yD2g2";

  return admin
    .firestore()
    .collection("users")
    .doc(uid)
    .get()
    .then(documentSnapshot => {
      var user = documentSnapshot.data();

      console.log("fcmToken: " + user.fcmToken);

      var payload = {
        notification: {
          title: "Push notification TITLE HERE",
          body: "Body over here is our message body..."
        }
      };

      return admin
        .messaging()
        .sendToDevice(user.fcmToken, payload)
        .then(function(response) {
          // See the MessagingDevicesResponse reference documentation for
          // the contents of response.
          return console.log("Successfully sent message:", response);
        })
        .catch(function(error) {
          throw new console.log("Error sending message:", error);
        });
    });
});

我的功能日志中什么也没有。记录器消息甚至不会出现。就是这样:

Function execution took 15 ms, finished with status code: 304

P.s。我使用的是实际的ios设备,而不是模拟器。

0 个答案:

没有答案