如何在Node.js中设置FCM推送优先级

时间:2019-05-09 04:33:38

标签: node.js push-notification

我需要在Android设备上发送高优先级的推送通知。我已经实施了FCM。当我取消注释优先级部分时,FCM会给出“未定义”作为响应。

     FCM(deviceToken, message, badge, metadata={},time_to_live=false){
     return new Promise((resolve, reject) => {
     let fcm = new FCMlib(this._fcm_server_key);
      /*Send notification to Android Device*/
       var pushParam = {
       to: deviceToken,
       data : {
       title: message, //'Title of your push notification',
       body: message,
       metadata: metadata
},
    // android:{
    // priority:high
    // },
   time_to_live: 10 ,
//The time in seconds
};
if(time_to_live === true){
delete pushParam.time_to_live;
}
  fcm.send(pushParam, (err, response) => {
    if(err){
    console.log('err---1 ',err);
     reject(err);
  }
    if(response) {
    /*update user badge*/
    console.log('response--- ',response);
    this.mysql.query("UPDATE `user_device_token` SET badge = ? WHERE ` 
  device_token` = ?", [badge, deviceToken])
   .then(result => {
   /*badge would be update*/
});
    resolve(response);
}
});
});
}

0 个答案:

没有答案