chemerisuk / cordova-plugin-firebase-messaging

Cordova plugin for Firebase Cloud Messaging
MIT License
164 stars 160 forks source link

Foreground messaging and onMessage() onBackgroundMessages() not working #137

Closed jkufrin closed 3 years ago

jkufrin commented 4 years ago

I can receive background messages on both Android and iOS. Foreground messages fail on both. I can't get onMessage() or onBackgroundMessage to trigger. RequestPermission comes back null.

I've scanned through all the open and closed issues and tried everything I can find. I want to be able to get foreground messages and also get both types of message observables working.

I wait until platform is ready before initializing. I'm using requestPermission({forceShow: true}) I'm sending from console.firebases.google in the Cloud Messaging tab I've tried custom data fields with: content-available=1 content_available=1 contentAvailable=1

Ionic 5.4.16 cordova 9 ios 5.1.1 android 8.1.0 cordova-plugin-ionic-webview 4.1.3 cordova-plugin-firebase-messaging 4.3.1 @ionic-native/firebase-messaging 5.24.0

xae217 commented 4 years ago

I am also running into the same issue, but only on iOS. Any luck solving this? Adding content-available:1 did not work.

sagrawal31 commented 4 years ago

Working fine for me!

xae217 commented 4 years ago

@sagrawal31 Do you mind showing me what your payload looks like? I am not sure if there is something incorrect in my payload preventing the methods from triggering in iOS.

sagrawal31 commented 4 years ago

@xae217 I'm sending the payload normally in the notification from the backend server. Even, I tried with Firebase console and the callbacks are getting called as well.

I see you have listed ionic dependency so if you are using Ionic, have you wrapped your callback data to this.ngZone.run(() => {});?

jkufrin commented 4 years ago

I upgraded to plugin version 4.4.0 and I'm finally getting getting the message data back in the onBackgroundMessage() for iOS. I'm still not getting foreground messages though. Android only gets background messages and does not get the callback data.

radhakrishnan308 commented 4 years ago

Please refer the documentation https://firebase.google.com/docs/reference/admin/node/admin.messaging.MessagingOptions#optional-contentavailable

contentAvailable: true

vivekkchaugule commented 3 years ago

@xae217 I'm sending the payload normally in the notification from the backend server. Even, I tried with Firebase console and the callbacks are getting called as well.

I see you have listed ionic dependency so if you are using Ionic, have you wrapped your callback data to this.ngZone.run(() => {});?

On Ionic Native/ Angular Do =>

import { Injectable, NgZone } from '@angular/core';
import { FirebaseMessaging } from '@ionic-native/firebase-messaging/ngx';

constructor(private fcm: FirebaseMessaging, private ngZone: NgZone) { }

this.fcm.onMessage().subscribe(notification => {
      this.ngZone.run(() => {
         // Access Notification here.
        alert(JSON.stringify(notification));
      })
 });

Thanks @sagrawal31