简体   繁体   中英

Ionic Firebasex don't work in background (iOS)

I'm working with Ionic3 and using FirebaseX Cordova Plugin (because firebase plugin it's not working at all) and when the App is foreground (opened) the message get in the App (not as a notification) perfect, but when in background (using another app) the notification don't show... when I open back the App, the message get in the App (not as a notification)...

I'm using the Author example EXACTLY (only changed the bundle id so I could register as a Firebase Project)

I use a paid developer account, I have defined a APN, uploaded to firebase etc.

Activate the Remote Notification in Capabilities (both on Push and Background)

But still...

Something strange is that when the App opens, it says in the log:

2019-10-25 11:20:50.152424-0300 FirebaseX Ionic 3 Example[560:180512] FCM direct channel = true

and when the App goes background, the login says:

2019-10-25 11:20:50.152424-0300 FirebaseX Ionic 3 Example[560:180512] FCM direct channel = false

And when I open the App again it goes back to true again, and receive the notification!

I know that FCM is Firebase Cloud Messagin, so... but I don't know why it turns false

Please, help! Thanks!

I found the solution. Maybe it helps someone... Now with the FirebaseX Cordova Plugin You need to ask for permission explicitly (with the old firebase cordova plugin, was automaticly asked...)

insert this code:

this.firebasePlugin.grantPermission(function(hasPermission){
    console.log("Permission was " + (hasPermission ? "granted" : "denied"));
});

and that's it (if the user say 'yes'!)

In firebasex cordova plugin you have to ask for permission like this.

You can only call grantPermission() if hasPermission() returns false:

window.FirebasePlugin.hasPermission(function(hasPermission){
if(!hasPermission){
    window.FirebasePlugin.grantPermission(function(permissionGranted){
        if(permissionGranted){
            console.log("Permission granted");
        }else{
            console.warn("Permission denied");
        }
    });
}else{
    console.log("Permission already granted");
}

});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM