我的应用程序只是订单应用程序,我希望管理员在下达新订单时收到通知。 为此,我使用Firebase函数将通知发送给具有令牌ID的设备。
int main()
{
FILE* in = fopen("lis.csv", "r");
int count=0;
int error=0;
int x, y;
typedef struct {
int x;
int y;
} COORD;
COORD array[999]={0};
if (in == NULL) {
printf("Can't open in.txt");
fclose(in);
return 1;
}
while(!feof(in))
{
if (fscanf(in, "%d,%d\n", &x, &y) != 2) {
printf("Cant read file.");
error=1;
break;
}
array[count].x=x;
array[count].y=y;
count++;
}
return error;
}
尽管我在控制台日志中收到了成功响应消息,但我的Android手机无法收到任何通知。
'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);
});
});
});
我的代码有什么问题。我是Firebase的新手。我需要你的帮助。
答案 0 :(得分:0)
您是否在后台运行应用程序进行了检查?您可以共享firebaseMessagingService的代码吗?