Open avencat opened 6 years ago
I'm using Local Notifications and this is not working for me.
onNotification
is not called on iOS when the app is in the background (was opened then pressed home button). I'm using the latest version and I call appStart
on root component. I also tried the setTimeout
mentioned above and no luck.
Here's my scenario:
localNotification
to be scheduled 20 seconds after I open the app.onNotification
is not calledI event tried calling showInitialNotification
when appState
changes and this returns null
for the notification. I also put a debug point on the native side to see if getInitialNotification
has any data and it doesn't have any data (nil
) for both initialNotification
and initialLocalNotification
.
Here's how I create a notification:
const payload = {
title: 'Some Test Title',
message: 'Test Summary',
userInfo: {
target: 'Details',
key: 'myKeyID',
name: 'myName'
};
PushNotification.localNotificationSchedule({
...payload,
date: new Date(Date.now() + (20 * 1000)) // in 20 secs
});
The onNotification
is called correctly when the app is killed and opened from a cold start (through a scheduled local notification). However, it is not called when the app is in the background (I assuming the app is in the background state when I press the home button and wait for 20 seconds).
I have also configured the Background modes as mentioned in the docs:
I've spent the past few days debugging iOS notifications trying to solve this 😠Would be great if @calcazar or anyone else has ideas I can try.
@Eyesonly88 did you ever resolve this? I am facing this same exact issue.
^ nope. Still an issue.
Does this issue have any solution?
avencat's workaround doesn't work for me. Here are more details:
This fixed it for me! https://github.com/zo0r/react-native-push-notification/issues/1272 Setting the activity launch mode like that seems to have wider implications, though. Wonder how safe this is.
Found the solution - fortunately, it is most straightforward.
This package depends on @react-native-community/push-notification-ios
for the iOS implementation. And in the README to that package, there are clear instructions on adding event handlers to AppDelegate to receive notifications while the app is running. Following the instructions resolved this issue for me.
So what's missing is a link from this README to that README.
Hi, I have an issue on iOS, indeed, the
onNotification
callback is not called when the app is launched and it was not on background or anything, just cold start with a click on anotification
.For information, I do have
PushNotification.appStart()
on my rootcomponentDidMount
method. And this is working when the app is in background and I click on a notification.[EDIT] It works if I use a
on my
componentDidMount
(same forPushNotification.setApplicationIconBadgeNumber(0)
)