6.1 C
London
Monday, February 12, 2024

Firebase flutter occasion.getInitialMessage() returning null (IOS) when the notification is opened in terminated state


I’m encountering a problem with redirecting customers to a selected display screen in my iOS software developed in Flutter after they click on on a push notification obtained by Firebase Cloud Messaging. This is the situation:

In my Flutter iOS software, push notifications are obtained through Firebase Messaging. Upon clicking a notification, the person ought to be redirected to a selected display screen. The info for these notifications is being despatched from a Node.js server utilizing the Firebase Legacy API.

This is the code snippet for sending notifications from the Node.js server:

const response = await fetch("https://fcm.googleapis.com/fcm/ship", {
          technique: 'POST',
          headers: {
            'Content material-Sort': 'software/json',
            'Authorization': `Bearer ${server_key}`,
            },
          physique: JSON.stringify({
            registration_ids: tokens,
            notification:{
              title:title,
              physique:physique
            },
            information:{
              // ...some information
            },
            content_available: true
          })
        })

The problem arises when the appliance is terminated: the message retrieved from FirebaseMessaging.occasion.getInitialMessage().then((message) {}) returns null. Consequently, I’m unable to entry message.information, stopping the redirection of the person to the precise display screen.

I’ve tried inserting the getInitialMessage operate in varied places, comparable to predominant.dart or bottom_navigation.dart, however it persistently returns null.

Nevertheless, there are some exceptions: often, when the app is opened from a notification after some delay, the notification is obtained, and redirection works as anticipated. However this conduct is inconsistent.

I’m confused by this conduct. Might there be any restrictions from the iOS aspect on receiving payload when the app is terminated? In that case, are there any different strategies to realize the identical performance? Any insights or recommendations can be drastically appreciated.

Latest news
Related news

LEAVE A REPLY

Please enter your comment!
Please enter your name here