Please provide the following:
- SDK Version: 14.19.1
- Platforms(Android/iOS/web/all): android
- Add the appropriate “Tag” based on what Expo library you have a question on. notifications
I receive notifications, when app fore/background it successfully triggers, but when app closed it fails to trigger.
I have the issue on local expo app (android emulator) or if i push app to store and use physical device.
I have read NotificationResponseReceivedListener
needs to be as high as possible as I understand the notification can drop before the app completely loads. I also read you can use useLastNotificationResponse
as a mechanism to catch missed notifications.
There looks to be many recent posts relating to this working. It is not clear if this works within android emulator as the documentation is not clear (I created a separate thread about the docs),
What seems to be unique in my case is the use of Stack.Navigator
.
I did wrap the IF statement within a useeffect but this returned an error " Rendered more hooks than during the previous render in Reactjs"
This is also simplified, there are more screens to get notification permissions etc. I am simply focusing here on triggering a notification from a closed app.
App.js
import ‘react-native-gesture-handler’;
import React from ‘react’;
import * as Notifications from ‘expo-notifications’;
import { NativeBaseProvider } from ‘native-base’;
import { NavigationContainer } from ‘@react-navigation/native’;
import { createStackNavigator } from ‘@react-navigation/stack’;
import { HomeScreen } from ‘./views/homescreen’
import { EventScreen } from ‘./views/eventscreen’
import { theme } from ‘./constants/extendTheme’;
const Stack = createStackNavigator();
function App() {
const lastNotificationResponse = Notifications.useLastNotificationResponse();
if (
lastNotificationResponse
// &&
// lastNotificationResponse.notification.request.content.data.url &&
// lastNotificationResponse.actionIdentifier === Notifications.DEFAULT_ACTION_IDENTIFIER
) {
console.debug(lastNotificationResponse.notification.request);
}
return (
<Stack.Navigator
initialRouteName=“Home”
screenOptions={({ route, navigation }) => ({
headerShown: false
})}
>
<Stack.Screen name=“Home” component={HomeScreen} />
<Stack.Screen name=“Event” component={EventScreen} />
</Stack.Navigator>
);
}
export default App;