简体   繁体   中英

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.

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.

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.

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. 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. In your app, you can get the device's ANDROID_ID and save it to the installation: `

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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