2016-11-17 89 views
0

我已經通過Jboss 6.4部署了UnifiedPush,我可以訪問admin ui並創建新的應用程序。 我試圖建立一個新的應用程序,以測試從管理控制檯的推送通知。我正在使用PhoneGap併爲Android平臺構建。 我在Genymotion Android模擬器上執行它。AeroGear UnifiedPush Cordova註冊設備

這是我的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). 有什麼問題?

+0

讓我看看你的config.xml請 –

+0

http://pastebin.com/RsuC0cmJ這裏是我的config.xml @HassanALi – slash89mf

+0

或從您的應用程序導航到cdvtes​​ts/index.html。請再次訪問它https://github.com/aerogear/aerogear-cordova-push –

回答

0

解決方案:pushServerUrl不能是"http://localhost:8080/ag-push/",您需要設置本地ip機在哪裏運行服務器。 (例如,"http://192.168.1.2:8080/ag-push/")。