首页 > 解决方案 > Android手机收不到使用firebase函数发送的通知

问题描述

我的应用程序只是订单应用程序,我希望管理员在下新订单时收到通知。为此,我使用 firebase 函数向带有令牌 ID 的设备发送通知。

'use-strict'
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotification = functions.database.ref('admin/{user_id}/notification/{notification_id}').onCreate((snapshot, context) => {

    console.log("hehehehehehehehe");
    const user_id=context.params.user_id;

    const getDeviceTokensPromise = admin.database().ref(`admin/${user_id}`).once('value');

    //let tokensSnapshot;
    //let tokes;

    return Promise.all([getDeviceTokensPromise]).then(result => {
        //const registrationToken= result[0].tokenid.val();
        //console.log(registrationToken);

        const payload = {
          notification: {
            title: 'You have a new follower!',
            body: 'Yeni sifaris var',
          }
        };

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

    });


});

尽管我在控制台日志中收到了成功响应消息,但我的 android 手机无法收到任何通知。

Successfully sent message: { results: [ { messageId: '0:1542910779596746%095eb9af095eb9af' } ],
canonicalRegistrationTokenCount: 0,
failureCount: 0,
successCount: 1,
multicastId: 6551370257673400000 }

我的代码有什么问题。我是火力基地的新手。我需要你的帮助。

标签: androidfirebasefirebase-cloud-messaginggoogle-cloud-functions

解决方案


推荐阅读