expo: useLastNotificationResponse returns null after clicking on a notification

Summary

When testing the useLastNotificationResponse, it returns null even when clicking on a notification when testing it using the Expo Go app. Same bug has been observed in production.

If the app is open, the useLastNotificationResponse hook correctly picks up the notification details when it is tapped on.

Managed or bare workflow? If you have ios/ or android/ directories in your project, the answer is bare!

managed

What platform(s) does this occur on?

Android

SDK Version (managed workflow only)

40

Environment

Expo CLI 4.4.3 environment info: System: OS: macOS 10.15.7 Shell: 5.7.1 - /bin/zsh Binaries: Node: 14.6.0 - /usr/local/bin/node npm: 6.14.13 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman Managers: CocoaPods: 1.10.1 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: iOS 14.4, DriverKit 20.2, macOS 11.1, tvOS 14.3, watchOS 7.2 IDEs: Android Studio: 4.0 AI-193.6911.18.40.6626763 Xcode: 12.4/12D4e - /usr/bin/xcodebuild npmPackages: @expo/webpack-config: ~0.12.45 => 0.12.68 expo: ^40.0.0 => 40.0.1 react: 16.13.1 => 16.13.1 react-dom: 16.13.1 => 16.13.1 react-native: https://github.com/expo/react-native/archive/sdk-40.0.1.tar.gz => 0.63.2 react-native-web: ~0.13.12 => 0.13.18 react-navigation: ^4.4.1 => 4.4.4 npmGlobalPackages: expo-cli: 4.4.3 Expo Workflow: managed

Reproducible demo or steps to reproduce from a blank project

  1. expo init my-project
  2. expo install expo-notifications
  3. Go to app.js and paste in the below
  4. Open the app with a physical device through the Expo Go app
  5. Close the opened app to make sure it is killed
  6. Send notification to the physical device Expo Token and click on it
  7. The app opens but the below console.log(useLastNotificationResponse) shows up as first undefined and then null
import { StatusBar } from "expo-status-bar";
import React from "react";
import { StyleSheet, Text, View } from "react-native";
import * as Notifications from "expo-notifications";

export default function App() {
  const lastNotificationResponse = Notifications.useLastNotificationResponse();

  console.log(lastNotificationResponse);
  return (
    <View style={styles.container}>
      <Text>Open up App.js to start working on your app!</Text>
      <StatusBar style="auto" />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: "#fff",
    alignItems: "center",
    justifyContent: "center",
  },
});


About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 20 (2 by maintainers)

Most upvoted comments

Facing the same issue in expo-50 as well. addNotificationResponseReceivedListener and useLastNotificationResponse only work when the app is in foreground.

I’m confused, why is this closed? Surely the expected behavior for this hook is that when the app is opened via a notification, it’ll return the notification object that was pressed. Only working if the app is foregrounded feels pretty useless.

I’m on SDK 41 and the problem still persists. As stated above, when the app is closed the notification is undefined then null, however, if the app is in the background then it correctly picks up the notification.

On "expo": "^48.0.9" with "expo-notifications": "~0.18.1", addNotificationResponseReceivedListener and useLastNotificationResponse only work when the app is in foreground.

I’m on expo 47.0.13 expo-notifications 0.18.1 This behaviour persists. (working in foreground and background , not when app killed) bare workflow