Reputation: 3417
I've created a cordova project with Visual Studio Code. I'm using this plugin: phonegap-plugin-push and I've follow the instructions.
I need to use notifications. I'm using Firebase and I've downloaded google-services.json, put it in my root, ran on Android and tested from Firebase cloud messaging. Everything works.
The problem: iOS. I've downloaded GoogleService-Info.plist, put on my root project and root platform ios. Downloaded the p8 certificates from apple developer console and put on Firebase console:
So, when I launch this on 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);
});
}
I receive the token on my iOS device (iPad & iPhone), but when I try to test it from Firebase, I can't see my devices registered token. Why? What I'm doing wrong?
Upvotes: 0
Views: 1316
Reputation: 405
I assume you are using the latest version of cordova-plugin-push (v2.2.3)?
Did you include the following in Cordova's config.xml?
<platform name="ios">
<resource-file src="GoogleService-Info.plist" />
</platform>
Failing this please check the value of data.registrationType
in your .on('registration')
callback. The value should be FCM
. If it's returning APNS
then the registrationId will be a raw APNs token, not a Firebase token, in which case something in your configuration is amiss.
Upvotes: 1