[英]Firebase cloud messaging does not work after successfully sendToDevice
I use Firebase Cloud Functions for sending notification via Cloud Messaging to iOS device. 我使用Firebase Cloud Functions通过Cloud Messaging将通知发送到iOS设备。
sendToDevice
method works great and returns success promise without any error or warning in Firebase Functions logs, but on iOS, notification is not showed. sendToDevice
方法的效果很好,可以在Firebase Functions日志中返回成功承诺,而不会出现任何错误或警告,但是在iOS上,不会显示通知。 If I send notification from Firebase Notifications dashboard, it works great and notification is showed on the device. 如果我从Firebase通知仪表板发送通知,则该通知会很好地工作并且通知会显示在设备上。 I don't know where I can have bug.
我不知道在哪里可以找到错误。 It's possible that bug is on iOS app side, even when it works like I said?
即使我像我说的那样工作,该错误也可能在iOS应用程序方面?
Firebase configuration: Firebase配置:
var functions = require('firebase-functions');
var admin = require('firebase-admin');
var config = functions.config();
admin.initializeApp(functions.config().firebase);
Part of cloud function: 云功能的一部分:
APP.services.firebase.admin.database().ref('tokens/' + userId).once('value', function(snapshot) {
var userDevicesTokens = [];
snapshot.forEach(function(childSnapshot) {
userDevicesTokens.push(childSnapshot.key)
});
if (userDevicesTokens.length === 0) {
console.warn('No tokens for user');
return;
}
var payload = {
data: {
title: options.title,
text: options.text,
type: options.type,
}
};
APP.services.firebase.admin.messaging().sendToDevice(userDevicesTokens, payload)
.then(function(response) {
console.log("Successfully sent message:", response);
})
.catch(function(error) {
console.log("Error sending message:", error);
});
})
Firebase Cloud Functions log: Firebase云功能日志:
11: 52: 43.952 AM info newChatMessageTrigger
Successfully sent message: {
results: [{
messageId: '0:15016....'
}],
canonicalRegistrationTokenCount: 0,
failureCount: 0,
successCount: 1,
multicastId: 589....
}
11: 52: 22.760 AM outlined_flag newChatMessageTrigger
Function execution took 604 ms, finished with status: 'ok'
11: 52: 22.252 AM outlined_flag newChatMessageTrigger
Billing account not configured.External network is not accessible and quotas are severely limited.Configure billing account to remove these restrictions
11: 52: 22.252 AM outlined_flag newChatMessageTrigger
Function execution started
I wrote to Firebase Support and problem was with message type. 我写信给Firebase支持,问题出在消息类型上。 In Firebase we have two types of messages: data and notification.
在Firebase中,我们有两种消息类型:数据和通知。 In this case we should use type notification ( see documentation ).
在这种情况下,我们应该使用类型通知( 请参阅文档 )。
Payload should looks like this: 有效负载应如下所示:
var payload = {
notification: {
title: options.title,
body: options.text,
},
data: {
type: options.type,
}
};
I think it is a issue with your payload. 我认为这与您的有效载荷有关。
Try this payload once with your firebase function, and let me know if you received notification on iOS. 使用您的firebase函数尝试一次此有效负载,并让我知道您是否在iOS上收到通知。
var payload = {
data: {
title: "Welcome to My Group",
message: "You have new messages"
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.