Phonegap和Parse.com推送通知IOS

时间:2013-06-14 13:24:03

标签: ios cordova parse-platform

所以我正在尝试设置PhoneGap IOS和Parse.com推送通知应用程序。我正在使用此插件https://github.com/mgcrea/cordova-push-notification向Apple注册设备并获取设备令牌。现在我需要将这些数据保存到Parse上的Installition类中。问题是,当我进行保存时,它会创建一个新的安装类。

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);
        }
    });

我也尝试过对其余api使用ajax调用而不去..

$.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);    
        }
    });

2 个答案:

答案 0 :(得分:1)

不要使用“安装”类。它只会创建一个新的Installation对象。要为Push通知创建Parse 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);
                    }
                });

答案 1 :(得分:0)

如果要更新数据,请确保“POST”不是“获取”

$.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);    
        }
    });

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