Closed sungwoncho closed 3 years ago
Before setup push notification, using cancelAllLocalNotifications method to remove all notifcation in notification central.
@sungwoncho Is the above code the exact code that you are using to show a local notification? In the above call, you are presenting a local notification right away which is why you are seeing a notification right away. In the logcat, I don't see any log about notification repeating every 1-2 seconds. The log clearly states that a notification with ID -992659542
at time 162000000
. Then no logs are seen for the same ID. The next log is seen for a completely different ID which is 15 hours after the previous one.
Remove the repeatType
option. I think there's a bug around it.
I suspect you had a date
set in the past.
In iOS if you set a past date with recurring, it will only show future reminders; however, Android will try to "catch up" and show every "missed" notification (which in our case was thousands).
Make sure to set ONLY future dates when setting up a repeated notification.
The other case is if you set date in future and device gets offline then you will get too many past notifications at once when device gets back ON. To avoid this you can do the following,
goto --> node_modules --> react-native-push-notifications --> android --> src --> main --> java --> com --> dieam --> reactnativepushnotification --> modules --> RNPushNotificationBootEventReceiver
then remove this line
rnPushNotificationHelper.sendToNotificationCentre(notificationAttributes.toBundle());
Ran into this same issue. with a local scheduled notification recurring daily.
Unclear what was happening until finally discovering it was from setting a date
in the past.
Wrote this helper function to ensure notifications were always set in the future:
import dayjs from 'dayjs'
function calcNext(date) {
// Make sure we are only setting notifications for dates in the future,
// to avoid Android going crazy showing backlogged notifications.
// see: https://github.com/zo0r/react-native-push-notification/issues/374#issuecomment-396089990
const now = dayjs()
// 1) set nextNotifTime to today's date
let nextNotificationTime = dayjs(date)
.year(now.year())
.month(now.month())
.date(now.date())
// 2) IF nextNotifTime date is < right now
if (nextNotificationTime.isBefore(now)) {
// THEN add 1day to NotifTime
nextNotificationTime = nextNotificationTime.add(1, 'day')
}
return nextNotificationTime.toDate()
}
@dsernst user will still get past notifications if device gets OFF and scheduled notifications time passed, then when user turn device ON, they will receive all past notifications. Make no changes, if you want user to see all notifications including past. Otherwise you should do following.
https://github.com/zo0r/react-native-push-notification/issues/374#issuecomment-579610393
It's not really clear in the docs, but I had to set the date property and switch to localNotificationSchedule, otherwise the notification occurs constantly, as described above.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions.
same issue here. i want to repeat notification every 10 minutes in Android, but notification pop up infinite time, to stop that i have to uninstall app, My code below:
import { Platform } from 'react-native'
import PushNotification, { Importance } from 'react-native-push-notification'
PushNotification.createChannel(
{
channelId: "oneoone",
channelName: "My channel",
channelDescription: "A channel to categorise your notifications",
playSound: false,
soundName: "default",
importance: Importance.HIGH,
vibrate: true,
},
(created) => console.log(`createChannel returned '${created}'`)
);
PushNotification.configure({
onNotification: function (notification) {
console.log('LOCAL NOTIFICATION ==>', notification)
},
popInitialNotification: true,
requestPermissions: Platform.OS === 'ios'
})
export const LocalNotification = () => {
PushNotification.localNotification({
channelId: 'oneoone',
autoCancel: true,
allowWhileIdle:true,
repeatType:'minute',
repeatTime:10,
bigText:
'Demo bigtext?',
title: 'demo title',
message: 'demo message',
vibrate: true,
vibration: 300,
playSound: true,
soundName: 'default',
actions: '["Confirm", "No"]'
})
}
versions
react-native-push-notification: 2.2.1 React Native: 0.41.2 Android: 6
problem
When I specify
repeatType
in mylocalNotification
setting object, the notification repeats constantly every 1~2 seconds.Here is how I am using this package. The code below is fired once and once only:
No matter what the value is for
repeatType
the notification repeats constantly every 1~2 seconds. I tried to includedate
but doing so did not fix the problem. If I removerepeatType
from the object, the problem goes away and notification shows once.Here is my logcat:
Any ideas?
more info
I had to upgrade build.gradle due to the issues related to https://github.com/zo0r/react-native-push-notification/issues/252
android/app/build.gradle