I created a simple Expo push notification app, and trying to send push notification using expo push token. I’m following expo documentation.
- When app is open - notification received
- When app is in background - not receiving
- When app is killed/closed - not receiving
Any guide, help documentation or example will be appreciated.
import * as Notifications from 'expo-notifications'
import * as TaskManager from 'expo-task-manager'
import * as BackgroundFetch from 'expo-background-fetch'
import * as Location from 'expo-location'
const LOCATION_TASK_NAME = 'background-location-task';
const requestPermissions = async () => {
const { status } = await Location.requestBackgroundPermissionsAsync()
if (status === 'granted') {
await Location.startLocationUpdatesAsync(LOCATION_TASK_NAME, {
accuracy: Location.Accuracy.Balanced,
});
}
};
TaskManager.defineTask(LOCATION_TASK_NAME,({data,error})=>{
if(error){
alert('Something went wrong with background locations')
}
if(data){
alert('Something went right with background locations')
const{locations} = data
}
})
useLayoutEffect(() => {
registerForPushNotificationsAsync().then(token => setExpoPushToken(token));
notificationListener.current = Notifications.addNotificationReceivedListener(notification => {
setNotification(notification);
});
responseListener.current = Notifications.addNotificationResponseReceivedListener(response => {
//console.log(response);
});
return () => {
Notifications.removeNotificationSubscription(notificationListener.current);
Notifications.removeNotificationSubscription(responseListener.current);
};
}, []);
function handlerNotification() {
schedulePushNotification()
return () => {
Notifications.removeNotificationSubscription(notificationListener.current);
Notifications.removeNotificationSubscription(responseListener.current);
};
}