AppState changes to active when app receives notification in killed state
See original GitHub issueI am able to receive notification in all 3 states (killed/foreground/background).
The data gets printed in console when the notification arrives, however I was not receiving any data from the notification when clicked on it from the notification tray.
- When I just send data, I can see the data getting printed in console the moment I send the notification but no icon in the notification array,
const payload = {
data: {
title: 'Hi',
body: 'body',
message: 'Message',
}
}
- When I just send data with notification, I can see icon in the notification array, but when I click on it, there is no data passed to the application in background and killed state
const payload = {
data: {
title: 'Hi',
body: 'body',
message: 'Message',
},
notification: {
title: 'Hi',
body: 'body',
message: 'Message',
}
}
- Updated: When I just send data with custom_notification, I can see icon in the notification array with data getting printed in the console as soon as the notification arrives in the notification tray, but when I click on it, there is no data passed to the application in background and killed state.
const payload = {
data: {
custom_notification: {
title: 'Hi',
body: 'body',
message: 'Message',
}
},
}
So, finally I decided to save data in asyncStorage whenever I receive the notification and if the user clicks on it I retrieve the notification data from storage. For this I heavily rely on appState.
The main problem here is that, when app is in killed state, I manage to store the data, but my function is unable to run as the AppState
gets set as active
when the notification arrives in killed state. Now when I click on the notification the AppState still remains active
and my handler does not run at all.
RN: 0.45.1, FCM: 13.3.1
Issue Analytics
- State:
- Created 6 years ago
- Comments:21 (7 by maintainers)
Top GitHub Comments
@balapkm you need to store the notification payload when it arrives in sleep/killed state using AsyncStorage and then when the user actually clicks on it, read it from AsyncStorage.
If you add a listener for killed state you will notice that the app receives the payload in killed state but when the user clicks on the notification the payload gets lost.
@sahil290791 perhaps I should merge sdk-26 into main as it is getting stable