简体   繁体   English

Ionic Firebasex 不能在后台运行 (iOS)

[英]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)...我正在使用 Ionic3 并使用 FirebaseX Cordova 插件(因为 firebase 插件它根本不工作),但是当应用程序处于前台时(打开应用程序时)另一个应用程序)通知不显示...当我打开应用程序时,消息进入应用程序(不是通知)...

I'm using the Author example EXACTLY (only changed the bundle id so I could register as a Firebase Project)我正在使用作者示例(仅更改了捆绑 ID,因此我可以注册为 Firebase 项目)

I use a paid developer account, I have defined a APN, uploaded to firebase etc.我使用付费开发者账号,我定义了一个 APN,上传到 firebase 等。

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 2019-10-25 11:20:50.152424-0300 FirebaseX Ionic 3 示例[560:180512] FCM 直接通道 = 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 2019-10-25 11:20:50.152424-0300 FirebaseX Ionic 3 示例 [560:180512] FCM 直接通道 = 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我知道 FCM 是 Firebase Cloud Messagin,所以......但我不知道为什么它会变成

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...)也许它可以帮助某人...现在使用FirebaseX Cordova 插件您需要明确请求许可(使用旧的 firebase cordova 插件,自动询问...)

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.在 firebasex cordova 插件中,您必须像这样请求许可。

You can only call grantPermission() if hasPermission() returns false:如果 hasPermission() 返回 false,您只能调用 grantPermission():

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");
}

}); });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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