I am using expo react native on a project and I am using the expo-notifications package within the project.
I have added "useNextNotificationsApi": true, to my app.json file
under the android object which is under the expo object so expo.android.useNextNotificationsApi : true.
I also have the experienceId set on the message I am sending to expo's server from my server, I am using the https://github.com/expo/expo-server-sdk-node package to do the sending.
messages.push({
to: red_user.fcm_token,
sound: 'default',
title: "Stylist Response",
body: "Stylist has agreed to fulfill the request",
data: {
experienceId: "@glamcentralng/GlamCentral",
order: order._id,
stylist_response: "agreed"
},
})
In my expo react native app I am using the expo-notifications package as I mentioned and I have the following setup in my class component.
import * as Notifications from 'expo-notifications';
.
.
.
.
componentDidMount() {
//Not working at all
Notifications.addNotificationReceivedListener( notification => {
console.log(notification);
this._handleNotification(notification)
});
//Working well
Notifications.addNotificationResponseReceivedListener(response => {
console.log(response);
});
this.registerForPushNotificationsAsyncNew();
}
The addNotificationReceivedListener does not receive the notification when it comes in, but I see it as a normal notification on my real Android device (I am NOT using an emulator). AS per the documentation when i click on the notification the addNotificationResponseReceivedListener should handle it and it does. So addNotificationReceivedListener does NOT work but addNotificationResponseReceivedListener works well.
One more thing to add is that I am getting a token in the function that does the registration as per the documentation.
Not sure how to fix this as I have checked other threads on here and github. Any help is appreciated.
question from:
https://stackoverflow.com/questions/65832863/addnotificationreceivedlistener-not-receiving-notification-in-expo-react-native 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…