在back4app中重复推送通知

时间:2017-12-04 10:47:06

标签: android ios push-notification cloud-code back4app

我通过调用云功能从iOS和Android发送推送通知,并且在每个设备中我得到5次单推通知。我正在使用back4app上托管的解析数据库。

云代码如下:

Parse.Cloud.define("push", function (request, response) {
    var query = new Parse.Query(Parse.Installation);
    var userID = request.params.user; 
    var message = request.params.message; 
    var notificationType = request.params.notificationType;
    var user = new Parse.User();
    user.id = userID;    
    query.equalTo('user', user);
    query.equalTo("allowPush", true);
    Parse.Push.send({
        where: query, 
        data: {
                alert: message,
                sound: 'default',
                "type": notificationType
              }
        },  { useMasterKey: true });
});

1 个答案:

答案 0 :(得分:2)

尝试在云代码功能结束时调用reponse.success和response.error函数。由于您的客户端代码在呼叫有效时未收到反馈,因此可能会尝试再次发送。

Parse.Cloud.define("push", function (request, response) {
    var query = new Parse.Query(Parse.Installation);
    var userID = request.params.user; 
    var message = request.params.message; 
    var notificationType = request.params.notificationType;
    var user = new Parse.User();
    user.id = userID;    
    query.equalTo('user', user);
    query.equalTo("allowPush", true);
    Parse.Push.send({
       where: query, 
       data: {
            alert: message,
            sound: 'default',
            "type": notificationType
       }
    },
    {
       success: function () { response.success(); },
       error: function(err) { response.error(err); },
       useMasterKey: true
    });
});