android - 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 }
我的代码有什么问题。我是火力基地的新手。我需要你的帮助。
解决方案
推荐阅读
- node.js - 如何在猫鼬的其他对象数组中更新特定对象的元素
- javascript - 如何添加到数组并获取值
- javascript - Javsacript for 循环给出奇怪的结果
- python - 如何打印在程序结束时完成的内部循环的总迭代次数?
- selenium - 在 Kantu 中使用“如果”
- javascript - Reactjs 无法读取智能合约?
- c++ - 如何使用 CredUIPromptForWindowsCredentials 验证凭据
- python - re.escape 返回不可用的目录
- mysql - sql REPLACE WHERE 两个外域
- sql-server - SSIS 宏无法打开 Excel