1

So I am trying to setup a PhoneGap IOS and Parse.com Push notification app. I am using this plugin https://github.com/mgcrea/cordova-push-notification to register the device with apple and get back the device token. Now I need to save that data to the Installition class on my Parse. Problem is when I do a save it creates a new installation class.

var Installation = Parse.Object.extend("Installation");
    var installation = new Installation();
    installation.save({badge: status.pushBadge, deviceToken: status.deviceToken, deviceType: status.type, installationId: appID}, {
        success: function(response){
            alert("seccuees " + response);
        },
        error: function(error){
            alert("error " + error.message);
        }
    });

I have also tried using a ajax call to the rest api and no go..

$.ajax({
        type: 'GET',
        headers: {'X-Parse-Application-Id':'miid','X-Parse-Rest-API-Key':'myid'},
        url: "https://api.parse.com/1/installations",
        data: {"deviceType": "ios", "deviceToken": "01234567890123456789", "channels": [""]},
        contentType: "application/json",
        success: function(response){
            alert("Success " + response);   
        },
        error: function(error){
            alert("Error " + error.message);    
        }
    });
4

2 回答 2

1

不要使用“安装”类。它只会创建一个新的 Installation 对象。要为推送通知创建解析安装对象,请使用“_Installation”。以下是做到这一点的方法。

var installation = new  Parse.Object("_Installation");;
installation.save({ channels: ['channelName'], deviceType: "android", installationId: id}, {
                success: function(response){
                    alert("success " + response);
                },
                error: function(error){
                        alert("error " + error.message);
                    }
                });
于 2014-12-26T02:16:46.800 回答
0

如果要更新数据,请确保类型是“POST”而不是“Get”

$.ajax({
        type: 'POST', // <============
        headers: {'X-Parse-Application-Id':'miid','X-Parse-Rest-API-Key':'myid'},
        url: "https://api.parse.com/1/installations",
        data: {"deviceType": "ios", "deviceToken": "01234567890123456789", "channels": [""]},
        contentType: "application/json",
        success: function(response){
            alert("Success " + response);   
        },
        error: function(error){
            alert("Error " + error.message);    
        }
    });

您还可以提供有关返回的错误的更多详细信息吗

于 2013-11-01T21:13:27.797 回答