我已经在Jboss 6.4上部署了UnifiedPush,我可以访问admin ui并创建新的应用程序。 我正在尝试构建一个新的应用程序,以便从管理控制台测试推送通知。我正在使用PhoneGap并为Android平台构建。 我在Genymotion Android模拟器上执行它。
这是我的index.html页面:
MyNamespace.MyClass
问题是在UnifiedPush管理控制台上没有注册任何设备。
我收到此错误: <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>
有什么问题?
答案 0 :(得分:0)
解决方案:pushServerUrl
无法"http://localhost:8080/ag-push/"
,您需要设置运行服务器的本地IP机器。 (例如"http://192.168.1.2:8080/ag-push/"
)。