Please provide the following:
- SDK Version: 40
- Platforms(Android/iOS/web/all): Android
- “notification”, “push”, “android”
its works well when app is running or in background but when app is closed or killed the notification doesnt fire the method notificationListener.current or responseListener.current. i saw that was a bug in SDK 38,
import * as Notifications from “expo-notifications”;
Notifications.setNotificationHandler({
handleNotification: async () => ({
shouldShowAlert: true,
shouldPlaySound: false,
shouldSetBadge: false,
}),
});
const HomeScreen = (props) => {
const dispatch = useDispatch();
const {navigation} = props || {}
const {navigate} = navigation || {}
const User = useSelector(state => state.auth.User);
const customer = useSelector(state => state.user.customer);
const {name, Url, emails, employee, devices,numbers, avatarUrl} = User || {};
const [isShowingSnackBar, setShowingSnackBar] = useState(false);
const [message, setMessage] = useState(false);
const {name: custormerName, logoUrl} = customer || {};
const [notificationId, setnotificationId] = useState(null);
const [notification, setNotification] = useState(false);
const notificationListener = useRef();
const responseListener = useRef();
//Check notification
useEffect(() => {
notificationListener.current = Notifications.addNotificationReceivedListener(notification => {
console.log('entrou notification');
console.log(notification);
const {request, date} = notification ||{}
const {content} = request ||{}
const {data} = content ||{}
const {annKey,type} = data ||{}
console.log(type);
if(annKey) {
// navigation.navigate('Detail', {annKey, updateFeed: true, onSelect},)
}
if(type===0 || type === 1){
dispatch(renewTokenActionV2(()=>{}));
}
});
responseListener.current = Notifications.addNotificationResponseReceivedListener(response => {
console.log('entrou 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},)
}
if(type===0 || type === 1){
dispatch(renewTokenActionV2(()=>{}));
}
});
return () => {
Notifications.removeNotificationSubscription(notificationListener);
Notifications.removeNotificationSubscription(responseListener);
};
}, []);