Firebase通知函数返回了未定义的预期承诺或值

时间:2019-12-18 17:27:05

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

以下是我的以下通知云功能。以前可以使用,但是现在我在应用程序内部或外部都没有收到任何通知。

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();


exports.observeFollowing = functions.database.ref('/following/{uid}/{followingId}')
    .onCreate((snapshot, context) => {

        const original = snapshot.val();

        var uid = context.params.uid
        var followingId = context.params.followingId

        console.log('User: ', uid, 'is following ', followingId);

       admin.database().ref('/users/' + followingId).once('value', snapshot => {

            var userWeAreFollowing = snapshot.val();

           admin.database().ref('/users/' + uid).once('value', snapshot => {

                var userDoingTheFollowing = snapshot.val();

                var payload = {
                    notification: {
                        title: "You have a new follower",
                        body: userDoingTheFollowing.username + ' is now following you',
                        sound: 'push.m4a',
                        badge: '1'
                    },
                    data: {
                        followerId: uid
                    }

                }

                admin.messaging().sendToDevice(userWeAreFollowing.fcmToken, payload)
                    .then((response) => {
                        console.log('Successfully sent message:', response);
                        return response
                    })
                    .catch((error) => {
                        console.log('Error sending message:', error);

                    });
            })
        })
    });

现在说A单击以跟随B,B没有收到任何东西,在B打开应用程序后,Firebase功能日志显示:

  

函数返回了未定义的预期承诺或值。

日志详细信息:它显示以下函数确实已执行。 enter image description here

上面的代码是否有问题?该功能以前工作过。我在appDelegate中的代码从未更改。现在不起作用。我不确定问题出在哪里。

还是有另一种编写通知云功能的方法?

0 个答案:

没有答案
相关问题