eCh*_*g00 4 node.js ios firebase
我正在尝试将通知从Node.js服务器发送到ios应用程序。如果我从Firebase控制台发送通知似乎可以正常工作,但是如果使用firebase-admin sdk从我的node.js服务器尝试发送通知则无法正常工作。
我遵循了https://firebase.google.com/docs/cloud-messaging/admin/send-messages中的教程。
我不明白的一件事是发送通知后的响应似乎可行。我没有得到回应。
{
"results": [
{
"messageId": "0:1511109840587284%a63b4c28f9fd7ecd"
}
],
"canonicalRegistrationTokenCount": 0,
"failureCount": 0,
"successCount": 1,
"multicastId": 7436388871122493000
}
Run Code Online (Sandbox Code Playgroud)
有人知道我在做什么错吗?
-编辑
这是发送通知的代码。admin是firebase-admin实例。
router.post('/notify', (req, res) => {
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "<database>.firebaseio.com"
});
var registrationTokens = [
'tokenFromIosApp'
];
var payload = {
data : {
body : 'TEST'
}
};
admin.messaging().sendToDevice(registrationTokens, payload)
.then((response) => {
console.log('Sent successfully.\n');
console.log(response);
res.status(statusCodes.Ok);
res.json(response);
})
.catch((error) => {
console.log('Sent failed.\n');
console.log(error);
res.status(statusCodes.InternalServerError);
res.json(error);
});
});
Run Code Online (Sandbox Code Playgroud)
Bob*_*der 10
要发送通知,有效负载必须使用notification密钥:
var payload = {
notification: {
title: 'My Title',
body : 'TEST'
}
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3646 次 |
| 最近记录: |