我会非常感激能帮助我的人 我需要检索每个设备和服务器phonegap的regid并正确地为我服务,但是当我在Android设备上模拟时,不再显示id
index.js
var app = {
initialize: function() {
this.bindEvents();
},
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
document.getElementById("toggleBtn").addEventListener('click', this.toggle, false);
},
onDeviceReady: function() {
console.log('deviceready event');
app.push = PushNotification.init({
"android": {
"senderID": "143828535864"
},
"ios": {},
"windows": {}
});
app.push.on('registration', function(data) {
console.log("registration event: " + data.registrationId);
document.getElementById("regId").innerHTML = data.registrationId;
alert(data.registrationId);
var oldRegId = localStorage.getItem('registrationId');
var idReg=jQuery("#idReg").val(data.registrationId);
if (oldRegId !== data.registrationId) {
// Save new registration ID
localStorage.setItem('registrationId', data.registrationId);
}
});
},
};
app.initialize();
和config.xml
<content src="index.html" />
<plugin name="cordova-plugin-whitelist" spec="1" />
<access origin="*" />
<allow-navigation href="*" />
<allow-navigation href="http://*/*" />
<allow-navigation href="https://*/*" />
<allow-navigation href="data:*" />
<allow-intent href="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
<allow-intent href="market:*" />
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
</platform>
<!--<plugin name="PushPlugin" value="com.plugin.gcm.PushPlugin" />-->
<plugin name="phonegap-plugin-push" spec="~1.7.2" />
<plugin name="cordova-plugin-whitelist" spec="1" />
<plugin name="cordova-plugin-device" spec="0.2.3" />
答案 0 :(得分:0)
首先检查Google开发人员控制台项目中的发件人ID,然后尝试以下更改。
app.push = PushNotification.init({
"android": {
"senderID": "143828535864"
}
});