I cannot get notifications from Firebase to appear. I followed the tutorial provided here. What could be the problem?
сode example :
setupPush: function() {
var push = PushNotification.init({
"android": {
"senderID": "966613396976",
"sound": true,
"vibration": true,
"badge": true
},
"browser": {},
"ios": {
"sound": true,
"vibration": true,
"badge": true
},
"windows": {}
});
push.on('registration', function(data) {
test(data);
var oldRegId = localStorage.getItem('registrationId');
if (oldRegId !== data.registrationId) {
localStorage.setItem('registrationId', data.registrationId);
}
});
push.on('error', function(e) {
console.log("push error = " + e.message);
});
push.on('notification', function(data) {
console.log('notification event');
navigator.notification.alert(
data.message, // message
null, // callback
data.title, // title
'Ok' // buttonName
);
});
}
};
It looks like you are using a deprecated version of the Phonegap push plugin. See this location for the newer version: https://github.com/phonegap/phonegap-plugin-push
This means that the init function should look like:
const push = PushNotification.init({
android: {
vibrate: true,
sound: true
},
ios: {
fcmSandbox: false,
alert: true,
vibrate:true,
badge: true,
sound: true
}
});
Please notice that the 'badge' parameter is not used in android. What's more is that you have to set a correct config.xml file:
This should be in there:
<platform name="android">
<resource-file src="google-services.json" target="/google-services.json" />
</platform>
<platform name="ios">
<resource-file src="push/GoogleService-Info.plist" />
</platform>
<plugin name="phonegap-plugin-push" spec="2.0.0" source="npm" />
This only works with the right version: https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/INSTALLATION.md