我用Visual Studio代码创建了一个cordova项目。我正在使用这个插件:
phonegap-plugin-push
我已经按照指示做了。
我需要使用通知。我使用的是Firebase,我下载了google-services.json,放在我的根目录中,在Android上运行,并通过Firebase云消息进行了测试。一切正常。
从apple developer console下载p8证书并放在Firebase console上:
所以,当我在index.js上启动这个时,ondeviceready:
onDeviceReady: function() {
this.receivedEvent('deviceready');
//alert("ciao");
app.push = PushNotification.init({
"android": {
"senderID": "xxxx"
},
"ios": {
"senderID": "xxxx",
"sound": true,
"vibration": true,
"badge": true
},
"windows": {}
});
app.push.on('registration', function(data) {
alert(data.registrationId);
console.log("registration event: " + data.registrationId);
document.getElementById("regId").innerHTML = data.registrationId;
var oldRegId = localStorage.getItem('registrationId');
if (oldRegId !== data.registrationId) {
// Save new registration ID
localStorage.setItem('registrationId', data.registrationId);
// Post registrationId to your app server as the value has changed
}
});
app.push.on('notification', function(data) {
console.log('notification event');
alert("qualcosa ricevuto: " + data.message + data.title);
});
app.push.on('error', function(e) {
//console.log("push error = " + e.message);
alert("push error = " + e.message);
});
}
为什么?我做错了什么?