【问题标题】:(Ionic 4) Can't receive notification with firebaseX when app is in foreground(Ionic 4)当应用程序处于前台时,无法使用 firebaseX 接收通知
【发布时间】:2020-01-17 04:13:43
【问题描述】:

我使用 FirebaseX 在我的应用程序中接收通知。 我在后台正确收到通知。但是当应用程序在前台时,什么都没有发生......

我已经搜索过这个问题,但对我没有任何帮助。 我尝试在数据内容中包含以下数据(当服务器调用 url 发送通知时) [通知前景] => 真 [点击] => 真的

这是我的插件列表:

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

当应用程序在后台时,我会收到通知,当我点击它时,我会收到警报消息和控制台日志。

但是当应用在前台时,什么都没有显示。

感谢您的帮助。

【问题讨论】:

    标签: firebase ionic-framework notifications foreground


    【解决方案1】:

    cordova-plugin-firebasex 插件不适用于 cordova-plugin-local-notification 插件我已经在我当前的 ionic ios 应用程序中遇到了这个问题,但使用android,它工作得很好

    根据@dpa99c

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

    详情请查看以下链接

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

    解决方案: 请使用带有 cordova-plugin-firebasexthis 本地通知插件它在 android 和 iOS 两个平台上都能完美运行

    【讨论】:

      【解决方案2】:

      使用 --prod 它似乎无需做任何其他事情就可以工作...... 它处于调试模式,无法正常工作

      【讨论】:

        【解决方案3】:

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

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

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

        { “名称”:“我的通知”, “通知”: { "body": "通知正文", "title": "通知标题" }, “数据”: { "notification_foreground": "真", } }

        .麦盖斯

        【讨论】:

          【解决方案4】:

          这与产品、QA 或调试模式无关。要触发前台消息,您需要在 Notification Payload 的数据对象下合并 "notification_foreground": "true"。

          例子:

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

          【讨论】:

            猜你喜欢
            • 2017-11-10
            • 1970-01-01
            • 1970-01-01
            • 2016-11-21
            • 1970-01-01
            • 2019-04-13
            • 2018-07-31
            • 2021-12-13
            • 1970-01-01
            相关资源
            最近更新 更多