im using react native expo and push notification works fine when app is running or in background but with the app is close. it doesnt call the method to handle the notification. I need to redirect to detail page. I tried to use function compoents and class components, tried to migrade to legacy notification and the new one.
import React, {useState, useEffect, useRef} from 'react'; import { Image, ScrollView, StyleSheet, Text, TouchableOpacity, Platform, View, Linking, } from 'react-native'; import * as Notifications from "expo-notifications"; const HomeScreen = (props) => { useEffect(() => { notificationListener.current = Notifications.addNotificationReceivedListener(notification => { const {request, date} = notification ||{} const {content} = request ||{} const {data} = content ||{} const {annKey,type} = data ||{} if(annKey) { // navigation.navigate('Detail', {annKey, updateFeed: true, onSelect},) } }); responseListener.current = Notifications.addNotificationResponseReceivedListener(response => { const {notification} = response ||{} console.log(notification); const {request, date} = notification ||{} const {content} = request ||{} const {data} = content ||{} const {annKey, type} = data ||{} if(annKey){ navigation.navigate('Detail', {annKey, updateFeed: true, onSelect},) } }); return () => { Notifications.removeNotificationSubscription(notificationListener); Notifications.removeNotificationSubscription(responseListener); }; }, []); } export default HomeScreen;
https://stackoverflow.com/questions/66548238/expo-notification-doesnt-fire-method-when-app-is-killed-closed March 09, 2021 at 09:54PM
没有评论:
发表评论