简体   繁体   English

Parse.com推送通知滞后和重复

[英]Parse.com push notifications lags and duplications

I integrated parse push notifications two days ago and it was working perfect. 两天前,我集成了解析推送通知,并且运行良好。 Today I made some more tests and I have huge lags, like parse notification was coming after 30 minutes instead of up to 5 seconds in previous days. 今天,我进行了更多测试,并且有很大的滞后,例如解析通知是在30分钟之后而不是前几天的5秒之后发出的。

In addition I have 4 devices and I received 11 "Pushes Sent" instead of 4. After a while of testing it starts to work normally, with only 4 "Pushes Sent", and after up to one minute instead of 30. 另外,我有4台设备,我收到了11个“已发送的推送”,而不是4个。经过一会儿的测试,它开始正常工作,只有4个“已发送的推送”,并且最多一分钟而不是30分钟。

In addition I get 5 times the same push on my developer device, where I am installing and uninstalling app frequently and 4 times on the other dev device, so it sums up to magic number 11. 另外,我在开发人员设备上的相同推动次数是我的5倍,在该设备上我经常安装和卸载应用程序,而在其他开发设备上则是4次,因此总和为11。

Is there are known issues with lags on Parse? 解析延迟是否存在已知问题? I need responses up to one minutes. 我需要最多一分钟的回复。 I though that it is reliable service. 我虽然这是可靠的服务。 It was temporary situation or this is normal? 是暂时的情况还是正常?

Every time you uninstall and install the app, you get a new installation object. 每次卸载并安装应用程序时,都会得到一个新的安装对象。 Unfortunately, the old Installation object never goes away. 不幸的是,旧的Installation对象永远不会消失。 What you need to do is to use some unique identifier for the device and just update the Installation if it exists. 您需要做的是为设备使用一些唯一的标识符,然后更新安装(如果存在)。

For example, let's say that you're trying to do this on Android. 例如,假设您正在尝试在Android上执行此操作。 In your app, you can get the device's ANDROID_ID and save it to the installation: ` 在您的应用程序中,您可以获得设备的ANDROID_ID并将其保存到安装中:

ParseInstallation.getCurrentInstallation().put("uniqueId",
                Settings.Secure.getString(getApplicationContext().getContentResolver(),
                        Settings.Secure.ANDROID_ID));

Then you can have a cloud function that is triggered every time a new installation is saved: 然后,您可以拥有每次保存新安装都会触发的云功能:

Parse.Cloud.beforeSave(Parse.Installation, function(request, response) {
Parse.Cloud.useMasterKey();
var query = new Parse.Query(Parse.Installation);
query.equalTo("uniqueId", request.object.get("uniqueId"));
query.first().then(function(duplicate) {
    if (typeof duplicate === "undefined") {
        console.log("Duplicate does not exist,New installation");
        response.success();
    } else {
        console.log("Duplicate exist..Trying to delete " + duplicate.id);
        duplicate.destroy().then(function(duplicate) {
            console.log("Successfully deleted duplicate");
            response.success();
        }, function() {
            console.log(error.code + " " + error.message);
            response.success();
        });

    }
}, function(error) {
    console.warn(error.code + error.message);
    response.success();
});
})

PS I've had that function for a long time and can't remember where I got it from, but I did not write it myself. PS我已经使用该功能很长时间了,不记得从哪里得到它,但是我自己没有写。

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

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