繁体   English   中英

iOS推送通知未收到(Firebase Cloud功能)

[英]iOS Push notification not receive (Firebase Cloud Functions)

大家! 我在iOS上收到通知时遇到问题。 任务的本质是这样的:将新记录添加到数据库时,您需要向所有符合条件的用户发送通知。 在Android上,一切正常,但在iOS上-不会收到通知。

它的云功能代码:

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}); 
});

证书已添加。 当我从控制台通过令牌推送通知发送到特定设备时,该通知会收到。

我会很高兴您的帮助。

UPD:在功能日志中,出现一条消息,通知已成功发送给用户。 这行:

console.log("createJob Successfully sent message:", response);
console.log("Success sending ",doc.id, " => ", doc.data().name);

我遇到了相同的情况,并使用了通知消息类型的有效负载而不是数据消息类型。 该问题已解决。

Firebase Cloud Messaging支持两种消息类型:通知消息和数据消息。 请参考官方文件

{
  "message":{
    "token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
    "notification":{
      "title":"Portugal vs. Denmark",
      "body":"great match!"
    }
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM