离子推使用$ http不适用于android(推送错误代码101)

时间:2015-11-19 07:05:07

标签: android ionic-framework

 push: function (tokens, message) {
      var privateKey = 'xxx';
      var appId = 'xxx';
      var auth = btoa(privateKey + ':');
      var req = {
        method: 'POST',
        url: 'https://push.ionic.io/api/v1/push',
        headers: {
          'Content-Type': 'application/json',
          'X-Ionic-Application-Id': appId,
          'Authorization': 'basic ' + auth
        },
        data: {
          "tokens": tokens,
          "notification": {
            "alert": message
          }
        }
      };

// Make the API call
      $http(req).success(function (resp) {
        // Handle success
        console.log(tokens);
        console.log(resp);
      }).error(function (error) {
        // Handle error
        console.log("Ionic Push: Push error...");
      });
    }

我正在使用上面的代码来推送通知。它进入了 成功处理程序并将使用的令牌和消息ID打印到控制台。但是,当我用消息ID检查状态时,它说的是推送错误代码101。

当我使用Ionic.io网站使用相同的令牌进行一次性通知屏幕时,它可以正常工作! 如何使用角度代码使其工作?

谢谢!

0 个答案:

没有答案