(Ionic 4)当应用程序在前台运行时,使用firebaseX无法接收通知

4

我使用FirebaseX在我的应用程序中接收通知。 当应用程序在后台时,我可以正确地接收通知。但是当应用程序处于前台时,没有任何反应...

我已经搜索了这个问题,但对我来说都没有用。 我尝试在数据内容中添加以下数据(当服务器调用URL发送通知时): [notification_foreground] => true [tap] => true

这是我的插件列表:

cordova-plugin-androidx-adapter 1.1.0 "cordova-plugin-androidx-adapter"
cordova-plugin-app-version 0.1.9 "AppVersion"
cordova-plugin-badge 0.8.8 "Badge"
cordova-plugin-device 2.0.3 "Device"
cordova-plugin-dialogs 2.0.2 "Notification"
cordova-plugin-fcm-with-dependecy-updated 3.0.0 "Cordova FCM Push Plugin"
cordova-plugin-file 6.0.2 "File"
cordova-plugin-firebasex 5.0.0 "Google Firebase Plugin"
cordova-plugin-ionic-keyboard 2.2.0 "cordova-plugin-ionic-keyboard"
cordova-plugin-ionic-webview 4.1.1 "cordova-plugin-ionic-webview"
cordova-plugin-local-notification 0.9.0-beta.2 "LocalNotification"
cordova-plugin-speechrecognition 1.1.2 "Speech Recognition"
cordova-plugin-splashscreen 5.0.3 "Splashscreen"
cordova-plugin-statusbar 2.4.3 "StatusBar"
cordova-plugin-whitelist 1.3.4 "Whitelist"

ionic信息:

Ionic:

   Ionic CLI                     : 5.2.8 
   Ionic Framework               : @ionic/angular 4.9.0
   @angular-devkit/build-angular : 0.13.9
   @angular-devkit/schematics    : 7.3.9
   @angular/cli                  : 7.3.9
   @ionic/angular-toolkit        : 1.5.1

Cordova:

   Cordova CLI       : 9.0.0 (cordova-lib@9.0.1)
   Cordova Platforms : android 8.0.0
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.1.1, (and 23 other plugins)

Utility:

   cordova-res : 0.5.1
   native-run  : 0.2.7

System:

   NodeJS : v10.16.0 
   npm    : 6.10.1
   OS     : Windows 10

订阅消息的代码...

this.firebase.onMessageReceived().subscribe(notification => {
            console.log('NOTIFICATION !!!!');
            console.log(notification);
            alert( JSON.stringify(notification) );
            if (notification['tap']) {
                this.navCtrl.navigateRoot('/test');
            } else {
                alert( JSON.stringify(notification) );
            }
        });

当应用程序在后台运行时,我会收到通知,当我点击它时,我会看到警报消息和控制台日志。
但是当应用程序在前台运行时,没有任何显示。
感谢您的帮助。
4个回答

1

cordova-plugin-firebasex插件与cordova-plugin-local-notification插件不兼容。我已经在当前的ionic ios应用程序中遇到了这个问题,但在安卓上,它完美地工作。

根据@dpa99c的说法:

问题在于这两个插件和cordova-plugin-local-notifications都实现了相同的UNUserNotificationCenterDelegate willPresentNotification委托。由于委托与其父类之间具有1:1的关系,因此只有一个委托被调用,在这种情况下,是响应于cordova-plugin-local-notifications创建的通知的cordova-plugin-firebasex委托。

请查看下面的链接获取详细说明。

https://github.com/dpa99c/cordova-plugin-firebasex/issues/230

解决方案: 请使用this本地通知插件和cordova-plugin-firebasex一起使用,在Android和iOS平台上都可以完美运行。


0

这与生产环境、QA或调试模式无关。要触发前台消息,您需要在通知负载的数据对象下加入“notification_foreground”:“true”。

例如:

{
 "to" : "your device token",
 "notification" :{
     "body" : "your message body",
     "title": "your title for notification"
 },
  "data":{
       "notification_foreground": "true"
  }
 }

0

使用 --prod 参数似乎可以正常工作,而不需要做其他任何事情... 只有在调试模式下才无法工作


0

来自 https://github.com/dpa99c/cordova-plugin-firebasex#background-notifications

如果应用程序在前台运行时收到通知消息,默认情况下它不会显示为系统通知。相反,通知消息负载将传递给onMessageReceived回调函数以供插件处理(tap将不被设置)。

如果在数据负载中包含notification_foreground键,则插件还将在应用程序在前台运行时接收通知消息时显示系统通知。例如:

{ "name": "my_notification", "notification": { "body": "Notification body", "title": "Notification title" }, "data": { "notification_foreground": "true", } }

.Maigais


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接