[英]iOS Push notification not receive (Firebase Cloud Functions)
everyone! 大家! I have problem with receiving notification on iOS. 我在iOS上收到通知时遇到问题。 The essence of the task is this: when a new record is added to the database, you need to send a notification to all users that match the criteria. 任务的本质是这样的:将新记录添加到数据库时,您需要向所有符合条件的用户发送通知。 On Android everything works correctly, but on iOS - notifications do not receive. 在Android上,一切正常,但在iOS上-不会收到通知。
It`s Cloud Functions code: 它的云功能代码:
exports.createJob = functions.firestore
.document('Jobs/{jobId}')
.onCreate(event => {
var jobObject = event.data.data();
var jobId=jobObject["jobId"];
var jobCategoryId=jobObject["categoryId"];
var db = admin.firestore();
var nodeToSearch="categoriesMap.".concat(jobCategoryId);
console.log("new job was added");
console.log("createJob nodeToSearch".concat(nodeToSearch));
db.collection('Companies')
.where(nodeToSearch, '==', true)
.get()
.then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
console.log("Company, that suit: ",doc.id, " => ", doc.data().name);
var registrationToken=doc.data().uidPhone;
var payload = {
data: {
notificationType: "NewJobNear",
message: "New Job For You",
jobId : jobId
}
};
if(registrationToken){
console.log("Try to Send to: ",doc.id, " => ", doc.data().name);
admin.messaging().sendToDevice(registrationToken, payload)
.then(function(response) {
// See the MessagingDevicesResponse reference documentation for
// the contents of response.
console.log("createJob Successfully sent message:", response);
console.log("Success sending ",doc.id, " => ", doc.data().name);
})
.catch(function(error) {
console.log("createJob Error sending message:", error);
console.log("Error sending ",doc.id, " => ", doc.data().name);
});
}
});
})
.catch(function(error) {
console.log("Error getting documents: ", error);
});
return event.data.ref.set({jobId:event.params.jobId},{merge:true});
});
Certificates have been added. 证书已添加。 And when I send to a specific device by token push notification from the console, the notification receives. 当我从控制台通过令牌推送通知发送到特定设备时,该通知会收到。
I will be very happy with your help. 我会很高兴您的帮助。
UPD: In the logs to the Functions, a message appears that the notification was successfully sent to the user. UPD:在功能日志中,出现一条消息,通知已成功发送给用户。 This lines: 这行:
console.log("createJob Successfully sent message:", response);
console.log("Success sending ",doc.id, " => ", doc.data().name);
I encountered the same case with you and used a payload of notification messages type instead of data messages type. 我遇到了相同的情况,并使用了通知消息类型的有效负载而不是数据消息类型。 The problem was fixed. 该问题已解决。
Firebase Cloud Messaging supports two message type: Notification messages and Data messages. Firebase Cloud Messaging支持两种消息类型:通知消息和数据消息。 please refer official document . 请参考官方文件 。
{
"message":{
"token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"notification":{
"title":"Portugal vs. Denmark",
"body":"great match!"
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.