【问题标题】:AeroGear UnifiedPush Cordova register devicesAeroGear UnifiedPush Cordova 套准设备
【发布时间】:2016-11-17 14:23:09
【问题描述】:

我已经在 J​​boss 6.4 上部署了 UnifiedPush,我可以访问管理 ui 并创建新的应用程序。 我正在尝试构建一个新应用程序,以测试来自管理控制台的推送通知。我正在使用 PhoneGap 并为 android 平台构建。 我在 Genymotion Android 模拟器上执行它。

这是我的 index.html 页面:

    <link rel="stylesheet" type="text/css" href="css/index.css" />
        <title>Hello World</title>

    <script>
    var app = {
    // Application Constructor
    initialize: function() {
      this.bindEvents();
    },
    // Bind Event Listeners
    //
    // Bind any events that are required on startup. Common events are:
    // 'load', 'deviceready', 'offline', and 'online'.
    bindEvents: function() {
      document.addEventListener('deviceready', this.onDeviceReady, false);
    },
    // deviceready Event Handler
    //
    // The scope of 'this' is the event. In order to call the 'receivedEvent'
    // function, we must explicitly call 'app.receivedEvent(...);'
    onDeviceReady: function() {
      app.receivedEvent('deviceready');
      var pushConfig = {
        pushServerURL: "http://localhost:8080/ag-push/",
        android: {
          senderID: "admin",
          variantID: "...",
          variantSecret: "..."
        }
      };
  push.register(app.onNotification, successHandler, errorHandler, pushConfig);

  function successHandler() {
    console.log('success')
  }

  function errorHandler(message) {
    console.log('error ' + message);
  }
  },
  onNotification: function(event) {
    alert(event.alert);
  },
  // Update DOM on a Received Event
  receivedEvent: function(id) {
    var parentElement = document.getElementById(id);
    var listeningElement = parentElement.querySelector('.listening');
    var receivedElement = parentElement.querySelector('.received');

    listeningElement.setAttribute('style', 'display:none;');
    receivedElement.setAttribute('style', 'display:block;');

    console.log('Received Event: ' + id);
  }
  };

    </script>

</head>

<body>
    <div class="app">
        <h1>PhoneGap prova</h1>
        <div id="deviceready" class="blink">
            <p class="event listening">Connecting to Device</p>
            <p class="event received">Device is Ready</p>
        </div>
    </div>
    <script type="text/javascript" src="cordova.js"></script>
    <script>app.initialize();</script>
</body>

</html>

问题是在 UnifiedPush 管理控制台上没有注册设备。 我收到此错误:ConnectException: failed to connect to localhost/127.0.0.1 (port 8080) after 30000ms: isConnected failed:ECONNREFUSED (Connection refused). 怎么了?

【问题讨论】:

  • 请给我看看你的config.xml
  • pastebin.com/RsuC0cmJ 这是我的 config.xml @HassanALi
  • 使用 更改 config.xml 中的起始页或从您的应用程序中导航到 cdvtes​​ts/index.html。请再次访问github.com/aerogear/aerogear-cordova-push
  • 我没有按照那个例子,所以我没有测试文件夹和其他。我还需要更改它吗?
  • 按照他们的建议尝试先测试,然后再做自己的实验。

标签: android cordova aerogear


【解决方案1】:

解决方法:pushServerUrl不能是"http://localhost:8080/ag-push/",需要设置服务器运行的本地ip机器。 (例如"http://192.168.1.2:8080/ag-push/")。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多