我一步一步地遵循了这些步骤来应用Firebase函数
1-我使用android studio连接到我的Firebase并连接到云消息传递并安装了依赖项
2-我通过终端安装了Firebase工具并登录(直到我编写此代码后,它才第一次起作用)
alias firebase="`npm config get prefix`/bin/firebase"
3-我在终端机firebase init
中编写了代码,然后选择我的项目和javascript,然后选择是安装npm
4-我确保我的index.js位于functions文件夹内
5-我用崇高的文字编写了这段代码以测试通知
'use strict'
const functions = require('firebase-functions');
const admin = require ('firebase-admin');
admin.initializeApp(functions.config()。firebase);
exports.sendNotification = functions.database.ref('/Notifications/{receiver_id}/{notification_id}')
.onWrite(event =>{
const receiver_id = event.params.receiver_id;
const notification_id = event.params.notification_id;
console.log('We have a notification to send to : ', receiver_id);
if(!event.data.val()){
return console.log('A notification has been deleted from the database : ',notification_id);
}
const deviceToken = admin.database().ref(`/Users/${receiver_id}/deviceToken`).once('value');
return deviceToken.then(result =>{
const token_id = result.val();
const payload = {
notification:{
title: "Friend Request",
body: "you have received a new friend request",
icon: "default"
}
};
return admin.messaging().sendToDevice(token_id, payload)
.then(response =>{
console.log('This was the notification feature.');
});
});
});
Blockquote
6-然后我使用firebase deploy
进行了部署,并等待了30秒
7-我在2个设备上安装了该应用程序并清理了数据库。 最后,firebase的功能部分中什么都没有显示
答案 0 :(得分:0)
您是否尝试过此命令“ firebase deploy --only functions”?