使用gcm(Android)和iOS(apn)针对单个请求获取Double PushNotification

时间:2018-07-18 07:22:37

标签: android ios node.js google-cloud-messaging apn

我收到双重通知。对于Android,我使用gcm,对于iOS apn。但是,当我检查日志时,它会给出1的成功响应。

以下是我得到的成功回复:

{"multicast_id":6917793905749047000,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1531893289157744%f5ad8b93f9fd7ecd"}]}

以下是用于通知的代码:

var sender = new gcm.Sender(rows[0].sender_key);
logger.info('Sender details :'+ sender)
var dt = new Date();
var formatted = dateFormat(dt, "UTC:yyyy-mm-dd HH:MM:ss");
var registrationToken = req.params.deviceToken;
logger.info('The registration token for the rider :'+ registrationToken);
var parcelId = req.params.parcel_id;
logger.info("Android notification, The parcel id is :" + parcelId);
var payload =  {
                    title: "Request",
                    Id: req.params.Id.toString(),
                    id:Id ,
                    time: formatted,
                    status: 'No'
                };
var message = new gcm.Message({
                    data: payload
                });
// Actually send the message
sender.send(message, { registrationTokens: registrationToken }, function (err, response) {
                    if (err){
                        logger.error("Error sending notification :" + err);
                    }else{
                        var queryTxt = "Update request_broadcast set request_sent_time = ? where id = ?";
                        var query = connection.query(queryTxt, [formatted, Id], function(err, rows) {
                            if (err) {
                                logger.error("Error sending notification :" + err);
                            } else if (rows.affectedRows == 0) {
                                //return res.send(401, {status:false,Msg:"request_broadcast not updated"});
                            } else {
                                logger.info("Response for rider request:" + response);
                                return res.send(200, {status:true,Msg:"Request Sent"});
                            }
                        });
                    } 
                });
            }

如果代码有任何问题,请通知我。从移动端有问题的可能性。

谢谢

0 个答案:

没有答案