【问题标题】:How to configure amazon SNS in Cordova mobile for receiving push notification如何在 Cordova 手机中配置亚马逊 SNS 以接收推送通知
【发布时间】:2016-02-19 13:29:53
【问题描述】:

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

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

但它在 android mobile 中出现错误。它显示网络错误,认为网络已连接并正常工作。

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

【问题讨论】:

    标签: cordova amazon-web-services push-notification ionic-framework amazon-sns


    【解决方案1】:

    我没有得到实际问题,为什么它没有从 ionic 移动应用程序调用。但是我删除了所有插件,然后尝试它开始工作。我有点知道某些插件在应用程序中添加或删除了一些与网络相关的权限

    【讨论】:

      猜你喜欢
      • 2017-09-05
      • 2017-11-14
      • 2021-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多