expo / expo

An open-source framework for making universal native apps with React. Expo runs on Android, iOS, and the web.
https://docs.expo.dev
MIT License
33.51k stars 5.36k forks source link

[expo-notification] getLastNotificationResponseAsync returns null #32006

Open RohovDmytro opened 3 days ago

RohovDmytro commented 3 days ago

Minimal reproducible example

https://github.com/expo/expo/issues/32006

What platform(s) does this occur on?

Android

Where did you reproduce the issue?

in a development build

Summary

The getLastNotificationResponseAsync returns null of expo-dev-client in a DEV mode.

  1. Kill the app.

  2. Sending a test Data type Message:

messaging().send(message)
  1. Listen to the incoming Message via @react-native-firebase/messaging.
setBackgroundMessageHandler(
    getMessaging(),
    async (data: FirebaseMessagingTypes.RemoteMessage) => {
      await scheduleNotificationAsyncByFCM(data);
    }
  );
  1. Trigger local notification.
export const scheduleNotificationAsyncByFCM = async (
  fcm: FirebaseMessagingTypes.RemoteMessage
) => {
  await scheduleNotificationAsync({
    content: {
      title: (fcm.data?.title || '') as string,
      body: (fcm.data?.body || '') as string,
      categoryIdentifier: NOTIFICATION_CATEGORY.REMINDER,
      data: {
        screen: fcm.data?.screen,
        screenParams: fcm.data?.screenParams,
      } as NotificationPayload,
      priority: AndroidNotificationPriority.MAX,
    },

    trigger: {
      channelId: NOTIFICATION_CHANNEL.DEFAULT,
      seconds: 1,
    },
  });
};

This way the notification gets displayed with a proper action, but pressing an action is not handled and getLastNotificationResponseAsync returns null. The release mode of the dev build works properly.

In other words, opening an app from a notifications make getLastNotificationResponseAsync return null. The docs:

https://docs.expo.dev/versions/latest/sdk/notifications/

true Killed useLastNotificationResponse or getLastNotificationResponseAsync

Environment

expo-env-info 1.2.0 environment info:
    System:
      OS: macOS 14.6.1
      Shell: 5.9 - /bin/zsh
    Binaries:
      Node: 20.12.0 - /private/var/folders/5l/mcrlgr6j0q17zlq54pkfblyw0000gn/T/xfs-0c31f9dc/node
      Yarn: 4.5.0 - /private/var/folders/5l/mcrlgr6j0q17zlq54pkfblyw0000gn/T/xfs-0c31f9dc/yarn
      npm: 10.5.0 - ~/.nvm/versions/node/v20.12.0/bin/npm
      Watchman: 2024.09.23.00 - /opt/homebrew/bin/watchman
    Managers:
      CocoaPods: 1.15.2 - /opt/homebrew/bin/pod
    SDKs:
      iOS SDK:
        Platforms: DriverKit 24.0, iOS 18.0, macOS 15.0, tvOS 18.0, visionOS 2.0, watchOS 11.0
      Android SDK:
        API Levels: 23, 31, 32, 33, 34
        Build Tools: 30.0.3, 33.0.0, 33.0.1, 33.0.2, 34.0.0, 35.0.0
        System Images: android-23 | Google APIs ARM 64 v8a, android-26 | Google APIs ARM 64 v8a, android-30 | AOSP ATD ARM 64 v8a, android-30 | Google APIs ARM 64 v8a, android-33-ext4 | Google Play ARM 64 v8a, android-33 | Google APIs ATD ARM 64 v8a
    IDEs:
      Android Studio: 2024.1 AI-241.18034.62.2411.12169540
      Xcode: 16.0/16A242d - /usr/bin/xcodebuild
    npmPackages:
      babel-preset-expo: ^11.0.15 => 11.0.15 
      expo: ^51.0.37 => 51.0.37 
      expo-router: 3.5.23 => 3.5.23 
      react: 18.3.1 => 18.3.1 
      react-dom: 18.3.1 => 18.3.1 
      react-native: 0.75.4 => 0.75.4 
      react-native-web: 0.19.11 => 0.19.11 
    Expo Workflow: bare

Expo Doctor Diagnostics

✔ Check Expo config for common issues
✔ Check package.json for common issues
✔ Check dependencies for packages that should not be installed directly
✔ Check for common project setup issues
✔ Check for issues with metro config
✔ Check if the project meets version requirements for submission to app stores
✔ Check for app config fields that may not be synced in a non-CNG project
✔ Check npm/ yarn versions
✔ Check Expo config (app.json/ app.config.js) schema
✔ Check native tooling versions
✖ Check that packages match versions required by installed Expo SDK
✔ Check for legacy global CLI installed locally
✔ Check that native modules do not use incompatible support packages
✔ Check that native modules use compatible support package versions for installed Expo SDK
vonovak commented 22 hours ago

Hello and thanks for reporting, I'm afraid the problem in this case is that the application starts from the killed state. We don't yet have good support for when the app is killed but it's something we're looking into.

Please note that the issue tracker requires "Minimal reproducible example" to be present. In simple cases we can do without it but with more complex issues like this one, it's hard to act on the issue if we don't have a reliable repro. Please try to add repros when you can, it saves us time and allows to resolve issues faster. Thank you 🙂