Skip to content

🔥 messaging().getInitialNotification() returns null after opening app from a quit state #8493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 task
Slisandro opened this issue Apr 26, 2025 · 3 comments
Labels
blocked: customer-response platform: android plugin: messaging FCM only - ( messaging() ) - do not use for Notifications type: bug New bug report

Comments

@Slisandro
Copy link

Slisandro commented Apr 26, 2025

Issue

When opening my app from a FCM notification (while app is quit), messaging().getInitialNotification() always returns null.
Notifications are working fine in background and foreground states.
I already checked common issues:

  • I'm not using react-native-splash-screen (I have a custom animated splash screen with Animated component).

  • I'm not using Notifee.

  • Using a physical Android device.

  • Tried sending notification and data payload.

  • Using the correct setBackgroundMessageHandler inside a useEffect.

  • expo-notifications has been uninstalled.

Still, getInitialNotification() keeps returning null.

Project Files

Click To Expand

package.json:

"dependencies": {
    "@expo/vector-icons": "^14.0.2",
    "@google/generative-ai": "^0.24.0",
    "@react-native-async-storage/async-storage": "^1.24.0",
    "@react-native-firebase/app": "^21.14.0",
    "@react-native-firebase/firestore": "^21.14.0",
    "@react-native-firebase/messaging": "^21.14.0",
    "@react-navigation/native": "^7.0.14",
    "axios": "^1.8.4",
    "expo": "~52.0.40",
    "expo-clipboard": "~7.0.1",
    "expo-constants": "~17.0.8",
    "expo-dev-client": "~5.0.20",
    "expo-font": "~13.0.4",
    "expo-linear-gradient": "^14.0.2",
    "expo-linking": "~7.0.5",
    "expo-router": "~4.0.19",
    "expo-secure-store": "~14.0.1",
    "expo-status-bar": "~2.0.1",
    "firebase": "^11.5.0",
    "firebase-admin": "^13.2.0",
    "formik": "^2.4.6",
    "google-auth-library": "^9.15.1",
    "react": "18.3.1",
    "react-native": "0.76.7",
    "react-native-country-codes-picker": "^2.3.5",
    "react-native-markdown-display": "^7.0.2",
    "react-native-paper": "^5.13.1",
    "react-native-reanimated": "~3.16.1",
    "react-native-safe-area-context": "4.12.0",
    "react-native-screens": "~4.4.0",
    "react-native-webview": "13.12.5",
    "toastify-react-native": "^6.0.0",
    "yup": "^1.6.1"
  } 

app.json:

{
  "expo": {
    "name": "apptest",
    "slug": "apptest",
    "version": "1.0.0",
    "orientation": "portrait",
    "scheme": "myapp",
    "userInterfaceStyle": "automatic",
    "newArchEnabled": true,
    "ios": {
      "supportsTablet": true,
      "googleServicesFile": "./GoogleService-Info.plist",
      "bundleIdentifier": "com.slisandro.apptest"
    },
    "android": {
      "adaptiveIcon": {
        "foregroundImage": "./assets/icon.png",
        "backgroundColor": "#ffffff"
      },
      "googleServicesFile": "./google-services.json",
      "package": "com.slisandro.apptest"
    },
    "web": {
      "bundler": "metro",
      "output": "static",
      "favicon": "./assets/icon.png"
    },
    "plugins": [
      "expo-router",
      "expo-secure-store",
      "@react-native-firebase/app"
    ],
    "experiments": {
      "typedRoutes": true
    },
    "extra": {
      "router": {
        "origin": false
      },
      "eas": {
        "projectId": "75c14a30-6da9-4007-b857-b886016aa243"
      }
    },
    "owner": "slisandro"
  }
}

eas.json:

{
  "cli": {
    "version": ">= 16.3.1",
    "appVersionSource": "remote"
  },
  "build": {
    "development": {
      "developmentClient": true,
      "distribution": "internal"
    },
    "preview": {
      "distribution": "internal"
    },
    "production": {
      "developmentClient": false,
      "distribution": "internal",
      "android": {
        "buildType": "apk"
      }
    }
  },
  "submit": {
    "production": {}
  }
}

Field for send test notification:

const sendNotification = async () => {
  const message = {
    token: "",

    notification: {
      title: "Notificación de prueba",
      body: "Esta es una prueba",
    },

    data: {
      screen: "/detail",
      id: "ID_PRODUCT",
    },
  };

  try {
    const response = await admin.messaging().send(message);
    console.log("✅ :", response);
  } catch (error) {
    console.error("❌ :", error);
  }
};

  • Platform that you're experiencing the issue on:
    • Android
  • Are you using TypeScript?
    • Yes & ^5.8.2
@Slisandro Slisandro changed the title [🐛] Bug Report Title - CHANGE ME 🔥 messaging().getInitialNotification() returns null after opening app from a quit state Apr 26, 2025
@MichaelVerdon MichaelVerdon added platform: android plugin: messaging FCM only - ( messaging() ) - do not use for Notifications labels Apr 28, 2025
@MichaelVerdon
Copy link
Collaborator

Hey there, thanks for the details on solutions you have tried. Can you please check the docs here to ensure correct usage of getInitialMessage() and onNotificationOpenedApp(). If that does not work can you show me a snipper or repo branch to investigate myself? Maybe you are not properly awaiting the initial message so the app opens before the message is received and handled properly.

@hirbod
Copy link
Contributor

hirbod commented Apr 28, 2025

I can confirm this issue. All listeners work, and getInitialMessage works fine on iOS, but it’s always null for us on Android when launched from a quit state. But I only tested "dev mode", so it might work in release when expo-dev-clients is not involved?

RN 0.79 with the new architecture enabled.

Unlike the OP, we do have expo-notifications installed, but we’re not setting up any listeners from Expo. We’re only using it to handle notification permissions and checks for Android and to setup the default channel (since those aren’t shipped by this library). Everything else works fine though.

@mikehardy
Copy link
Collaborator

I'm not using react-native-splash-screen (I have a custom animated splash screen with Animated component).

Do you handle the reason react-native-splash-screen is problematic? Do you handle the specific case where on Android 12 the intent isn't passed correctly for various reasons (it's subtle - check react-native-bootsplash for example)?

I recommend you remove the splash screen as a temporary measure to test things and make sure your splash screen code doesn't have a fault. A splash screen would be considered a violation of the principle of "minimum reproducible example" for the purposes of recreating this issue and it is such a classic source of problems on Android with initial notifications I can't justify spending any time investigating as long as a splash screen is involved and no minimum example is provided

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked: customer-response platform: android plugin: messaging FCM only - ( messaging() ) - do not use for Notifications type: bug New bug report
Projects
None yet
Development

No branches or pull requests

4 participants