【问题标题】:Phonegap and Parse.com Push Notifications IOSPhonegap 和 Parse.com 推送通知 IOS
【发布时间】:2013-06-11 03:58:23
【问题描述】:

所以我正在尝试设置 PhoneGap IOS 和 Parse.com 推送通知应用程序。我正在使用这个插件https://github.com/mgcrea/cordova-push-notification 向苹果注册设备并取回设备令牌。现在我需要将该数据保存到 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);
        }
    });

我也尝试过使用 ajax 调用其余 api 并且不行..

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

【问题讨论】:

  • 你能告诉我android的代码吗?

标签: ios cordova parse-platform


【解决方案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);
                    }
                });

【讨论】:

    【解决方案2】:

    如果要更新数据,请确保类型是“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);    
            }
        });
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-16
      • 1970-01-01
      • 1970-01-01
      • 2018-07-06
      • 1970-01-01
      相关资源
      最近更新 更多