I cannot get notifications to trigger when app closed

Please provide the following:

  1. SDK Version: 14.19.1
  2. Platforms(Android/iOS/web/all): android
  3. 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;

Ive managed to get it working. Some real odd behaviour until I got it working.
It seems lastNotificationResponse is essential for closed/killed apps.
Also lastNotificationResponse wont trigger within the android emulator. Notifications work and foreground or background app works, but not killed. Pushing this to internal playstore and physical device proved it was working. Wasted a lot of time on trying to get it to trigger in emulator.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.