Project - Expo Managed React nativeMy Expo version is "expo": "~51.0.14", "react-native": "0.74.2",
I used expo notifications@~0.28.9 for push notifications
addNotificationResponseReceivedListener is working fine when app is in foreground ,once app is killed or removed from background , it is not working properly .
import { useState, useEffect, useRef } from 'react'import * as Device from 'expo-device'import * as Notifications from 'expo-notifications'
import Constants from 'expo-constants'
export interface PushNotificationState {expoPushToken?: Notifications.ExpoPushTokennotification?: Notifications.Notification}
export const usePushNotifications = (): PushNotificationState => {Notifications.setNotificationHandler({handleNotification: async () => ({shouldPlaySound: true,shouldShowAlert: true,shouldSetBadge: false})})const intializestore = useInitializeStore()const homestore = useHomeStore()const navigation = useNavigation()const [expoPushToken, setExpoPushToken] = useState {registerForPushNotificationsAsync().then((token) => {setExpoPushToken(token)})//foregorundnotificationListener.current =Notifications.addNotificationReceivedListener((notification) => {setNotification(notification)})//backgroundresponseListener.current =Notifications.addNotificationResponseReceivedListener((response) => {handleNotificationResponse(response)})
return () => { Notifications.removeNotificationSubscription(notificationListener.current! ) Notifications.removeNotificationSubscription(responseListener.current!)}}, [])
return {expoPushToken,notification}}this is my code.can anyone please tell me the solution?