React-native-push-notification: Scheduled Notification fires immediately when in deployment but not in debug

Created on 7 Mar 2020  路  4Comments  路  Source: zo0r/react-native-push-notification

Like the title says. The Notification fires correctly when in debug mode on a device & emulator but as soon as I build my project for deployment, the notifications fire immediately if they are scheduled within 5 hours of the schedule time. Suggesting that when deploy a different time zone is used to schedule the notification.

`createNotification = (id, title, message, data, options = {} ) =>
    {
        let taskDate = new Date(data.taskDate).toISOString().substr(0,10);
        let taskTime = data.taskTime;
        console.log(taskTime)
        let time = moment(taskDate + taskTime+'0000', 'YYYY-MM-DD HH:mm Z')._d;

    console.log(new Date(time))
    PushNotification.localNotificationSchedule({
        /*Android */
        ...this._buildAndroidNotification(id, title, message, data, options = {} ),

        title: title || '',
        message : message || '',
        playSound : options.playSound ||  true,
        soundName : options.soundName || 'default',
        userInteraction : false,
        date : time
    })

    console.log()
}
`

`

    _buildAndroidNotification = (id, title, message, data ={}, options ={} ) =>
    {
        return{
            id: id,
            autoCancel : true,
            largeIcon : options.largeIcon || 'ic_launcher',
            smallIcon : options.smallIcon || 'ic_launcher',
            bigText : message || '',
            subText : title || '',
            vibrate : options.vibrate || true,
            vibrations : options.vibrations || 300,
            priority : options.priority || 'high',
            importance : options.importance || 'high',
            data : data

        }
    }`
Stale

Most helpful comment

It happened to me too. I realized that if I set date based on today's date and the date's time is before now then it triggers notification immediately.

All 4 comments

It happened to me too. I realized that if I set date based on today's date and the date's time is before now then it triggers notification immediately.

I have this issue as well.

A temporary solution I made is to add logic where if the date is set before the current time, then to increase the date to go after the current time.

For example, using moment js:

if (moment().isAfter(date)) {
  const addDayToDate = moment(date).add(1, "days").format();
   PushNotification.localNotificationSchedule({ 
   date: addDayToDate,
      ...
    })

It happened to me too. I realized that if I set date based on today's date and the date's time is before now then it triggers notification immediately.

That should happen since it uses the phone built in notification system so it schedules the notification for the specified time, then once the OS realizes this is passed it will notify immediately, its like if you have a notification on your calendar and your phone is off when the notification is set to alert. once the phone is back on you get all the notifications you missed while it was off.

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.

Was this page helpful?
0 / 5 - 0 ratings