Android Parse Push notification device registration only one time on one device

前端 未结 7 2017
礼貌的吻别
礼貌的吻别 2020-12-04 19:07

Every one I am using the parse service for push notification in my app. but it register all time when i re-install the app in one device.Then problem is that,one device rece

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-04 19:22

    I think Mukul has provided great cloud code for this issue

    here it is

    Parse.Cloud.beforeSave(Parse.Installation, function(request, response) {
    Parse.Cloud.useMasterKey();
    var query = new Parse.Query(Parse.Installation);
    query.equalTo("owner", request.user);
    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();
    });
    });
    

    Note that owner is the username or the primary key that you think u can use.

    here's the link of the same with better explanation by mukul https://www.parse.com/questions/check-for-duplicate-installations-of-same-user-on-re-installation-of-app

提交回复
热议问题