如何在 Cordova Mobile 中配置亚马逊 SNS 以接收推送通知

How to configure amazon SNS in Cordova mobile for receiving push notification

我正在使用离子框架开发 Cordova 应用程序。我想使用 amazon-sns 服务来推送通知。

我已经在应用程序中为浏览器配置了 amazon sdk。但是在浏览器中执行移动应用程序时,AWS.config.credentials.get 只有 return 个带有数据的成功对象,

但它在 android 移动设备中出错。它显示网络错误认为网络已连接并且正在工作。

sns.createPlatformEndpoint 方法也给出了凭据错误,您可以在屏幕截图中看到这两个错误。

这里还有代码截图

.run(function($cordovaPush,$rootScope) {

  var registerForSNS = function(gcmId){
    var params = {
      PlatformApplicationArn: 'my amazon arn', /* required */
      Token: gcmId, /* required */
      CustomUserData: 'STRING_VALUE'
    };

    sns.createPlatformEndpoint(params, function(err, data) {
      if (err) 
        console.log(err, err.stack); // an error occurred
      else{
          console.log(data.EndpointArn);
          alert(data.EndpointArn); 
       }              
    });
  } 


  AWS.config.region = 'us-east-1';
  AWS.config.update({
    credentials : new AWS.CognitoIdentityCredentials({
      IdentityPoolId: 'my Identity pool ID'
     })
  });
  var sns = new AWS.SNS();
  AWS.config.credentials.get(function(err) {
    if (err){
      console.log(err);
    } else{
      console.log(AWS.config.credentials);
      registerForSNS();
    } 
  });

  document.addEventListener("deviceready", function(){

     var androidConfig = {
      "senderID": "my sender id",
    };
    $cordovaPush.register(androidConfig).then(function(result) {
      // Success
      alert(JSON.stringify(result));
    }, function(err) {
      // Error
      alert(JSON.stringify(err));
    })

    $rootScope.$on('$cordovaPush:notificationReceived', function(event, notification) {
      switch(notification.event) {
        case 'registered':
          if (notification.regid.length > 0 ) {
            alert('registration ID = ' + notification.regid);
            registerForSNS(notification.regid); 
          }
          break;

        case 'message':
          // this is the actual push notification. its format depends on the data model from the push server
          alert('message = ' + notification.message + ' msgCount = ' + notification.msgcnt);
          break;

        case 'error':
          alert('GCM error = ' + notification.msg);
          break;

        default:
          alert('An unknown GCM event has occurred');
          break;
      }
    });    
  }, false);
});

我没有得到为什么它不是从 ionic 移动应用程序调用的实际问题。但我删除了所有插件,然后尝试它开始工作。我有点知道某些插件在 app

中添加或删除了一些与网络相关的权限