cordova-plugin-firebase: Problem with iOS notifications
Describe the bug Notifications does not appear.
Steps to reproduce the behavior:
1. npm i cordova
2. cordova plugin add cordova-plugin-firebase --save
3. cordova platform add ios
Expected behavior Notifications appear when app is closed or background
Implemented code
window.FirebasePlugin.getToken(function(token) {
console.log('token: ' + token);
}, function(error) {
console.error(error);
});
window.FirebasePlugin.hasPermission(function(data){
if (!data.isEnabled) {
window.FirebasePlugin.grantPermission().then(data => {
window.FirebasePlugin.subscribe('ios_test');
console.log('permission granted');
})
.catch(error => {
console.error('Error getting permissions', error);
return false;
});
}
else {
console.log('Already has permission');
window.FirebasePlugin.subscribe('ios_test');
}
});
Console Logs
[3214:2441143]token: eOPj1NEPqb0:APA91bEkVtc2CA...
[3214:2441143]Already has permission
[3214:2441278]5.7.0 - [Firebase/Messaging][I-FCM002024] Format '/topics/ios_test' is deprecated. Only 'ios_test' should be used in subscribeToTopic.
With Notification payload:
(
[notification] => Array
(
[title] => Title test
[body] => Body test
)
[data] => Array
(
[title] => Title test
[text] => Text test
)
[priority] => high
[to] => /topics/ios_test
)
Nothing happens. But with Data only payload:
(
[data] => Array
(
[title] => Title test
[text] => Text test
)
[priority] => high
[to] => /topics/ios_test
)
In this case, I get the data when the app is in foreground but no notification when the app is closed or in background.
[3231:2468704] Received data message: {
from = "/topics/ios_test";
text = "Text test";
title = "Title test";
}
Plugin Version
cordova-plugin-firebase 2.0.5
Smartphone (please complete the following information):
- Device: iPhone6
- OS: iOS 11.4.1
Additional context I know this is possible with this plugin, since I already had this version working. I feel like I’m missing something. Can you help me.
About this issue
- Original URL
- State: open
- Created 6 years ago
- Comments: 31
@charlie-rushton for the past two days i’ve spent 16+ hours trying to get this to work. these three steps worked for me:
Didn’t do anything else of your guide but this still fixed it for me. Thanks so much.
Hey @evinkuraga, yes I fixed this issue. Do you have a slack or email so I could send to you all of the stuffs I did? And If it did work, I’ll add it here on this thread to share it to others 😁
Hi, Add just
window.FirebasePlugin.grantPermission();
it works for me.
@RicardoMSFaria : Here is the exact code I have after the
ondeviceready
event.In firebase (here : https://console.firebase.google.com/project/YOUR-PROJECT/settings/cloudmessaging/ ), add the
.p12
fileTo test easily, you can launch Postman and import this collection :
It’s easier to debug