useLastNotificationResponse returns null after clicking on a notification
See original GitHub issueSummary
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
expo init my-project
expo install expo-notifications
- Go to app.js and paste in the below
- Open the app with a physical device through the Expo Go app
- Close the opened app to make sure it is killed
- Send notification to the physical device Expo Token and click on it
- 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",
},
});
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:8 (2 by maintainers)
Top GitHub Comments
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.
This was fixed in SDK 41 - https://github.com/expo/expo/issues/11933