导航菜单
首页 >  XMLHttpRequestUpload events not firing in Expo Go 49  > addNotificationResponseReceivedListener or useLastNotificationResponse is not firing when app is killed · Issue #11933 · expo/expo · GitHub

addNotificationResponseReceivedListener or useLastNotificationResponse is not firing when app is killed · Issue #11933 · expo/expo · GitHub

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?

相关推荐: