- SDK Version: 40
- Platform: Android
Hey guys, when I click at response Expo Push it’s open a new index.js and navigating to screen and after some seconds it return to my home screen, it’s required put expo push notification responseListener at root of project? on app.js? why it’s open a new index.js tab? My project is like this:
App.js:
<SocketContext.Provider value={socket}>
<AuthProvider>
<ChannelProvider>
<MessageProvider>
<Wrapper /> -> my sendpushnotifcation and responseListener.current
</MessageProvider>
</ChannelProvider>
</AuthProvider>
</SocketContext.Provider>
useEffect(() => {
registerForPushNotificationsAsync().then((token) =>
setExpoPushToken(token)
);
responseListener.current = Notifications.addNotificationResponseReceivedListener(
(response) => {
console.log("RESPONSE>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + response);
var data = response.notification.request.content.data;
console.log(
"info_request D-ATAAAAA-AAAAAAAAAA-AAAAAAAAAA-AAAA---AAAAAAAAA-AAAAAAAAA"
);
navigate("Room");
return () => subscription.remove();
}
// }
);
notificationListener.current = Notifications.addNotificationReceivedListener(
(notification) => {
setNotification(notification);
}
);
return () => {
Notifications.removeNotificationSubscription(notificationListener);
Notifications.removeNotificationSubscription(responseListener);
};
}, []);
async function sendPushNotification(
pushToken,
roomID,
favor,
respondent,
) {
// console.log(favor);
console.log(
"push sent!!!!!!!!!!!!" + pushToken,
roomID,
favor,
respondent,
);
const messageRequisitioner = {
to: pushToken,
sound: "default",
title: "Nova notificacione",
body: "[Foto]",
data: {
roomID: roomID,
requisitioner: state.currentUser,
requisitioner_token: expoPushToken,
favor: favor, //filtered footprint
},
};
const messageRespondent = {
to: pushToken,
sound: "default",
title: "Nova Informação em tempo real",
body: "Uma foto similar ksks",
data: {
roomID: roomID,
respondent: respondent,
requisitioner_token: expoPushToken,
favor: favor, //filtered footprint
},
};
await fetch("https://exp.host/--/api/v2/push/send", {
method: "POST",
headers: {
Accept: "application/json",
"Accept-encoding": "gzip, deflate",
"Content-Type": "application/json",
},
body: respondent
? JSON.stringify(messageRespondent)
: JSON.stringify(messageRequisitioner),
});
}