question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Foreground messaging and onMessage() onBackgroundMessages() not working

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7

github_iconTop GitHub Comments

1reaction
sagrawal31commented, May 2, 2020

@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(() => {});?

0reactions
vivekkchaugulecommented, Dec 12, 2020

@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

Read more comments on GitHub >

github_iconTop Results From Across the Web

FCM FirebaseMessaging.onMessageOpenedApp Won't work
Try this: FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage? message) { if ( ...
Read more >
Flutter Firebase Foreground and Background Messaging
Learn how to send cloud messaging. This push messaging are done by using onMessage and onBackgroundMessage handlers. FirebaseMessaging.
Read more >
Receive messages in a Flutter app - Firebase - Google
Notification messages which arrive while the application is in the foreground will not display a visible notification by default, on both Android and...
Read more >
Flutter: FCM — How to Navigate to a Particular Screen After ...
for receiving message when app is in background or foreground static Future<void> onMessage() async { FirebaseMessaging.onMessage.listen((RemoteMessage ...
Read more >
firebase_messaging | Flutter Package - Pub.dev
Flutter plugin for Firebase Cloud Messaging, a cross-platform messaging ... was tapped to open app. fixes getInitialMessage() & onMessageOpenedApp() .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found