【发布时间】:2021-04-04 00:04:45
【问题描述】:
我正在尝试通过以下代码向 iOS 触发推送通知。我已经实现了这个,当我通过 Firebase 控制台触发它们时它工作正常。但我无法通过云功能触发它们。
当我运行这个函数时,我得到{"error":{"message":"Bad Request","status":"INVALID_ARGUMENT"}}
我在这里错过了什么吗?
exports.testMessage = functions.https.onCall(() => {
console.log('test message started');
const registrationToken = 'fPxlvSiOYEX6gyGhSb5zZp:APA91bH3Q10Yjmo9Oa0Glx78_EZJQ3LO0B1PPWhfOZkTthOI7aP9uUsvzAq3EmYkfaswWIjsTR57NEKkr8BF2q4UbWH4-C5AqGv_XGvJp5C2EPbQ3cjL4zo0eGcSr3IP0PmSpYLjh1Sm';
var message = {
notification: {
title: 'Test title',
body:'Test body'
},
token: registrationToken // Token is inserted here.
};
return admin.messaging().send(message)
.then((response) => {
// Response is a message ID string.
console.log('Successfully sent message:', response);
return { 'message': 'sent' }
}).catch((error) => {
console.log('Error sending message:', error);
return { 'message': 'failed' }
});
})
【问题讨论】:
标签: ios node.js google-cloud-functions firebase-cloud-messaging apple-push-notifications