Scheduled local notifications are not triggered after phone reboot


#1

Hi,

My app schedules a set of notifications for the entire week. The notifications have the following shape:

createChannelAndroid: function createChannelAndroid(channelId, snackID) {
    if (Platform.OS === 'android') {
      Expo.Notifications.createChannelAndroidAsync(channelId, {
        name: `Next snack - ${snackID}`,
        sound: true,
        vibrate: [0, 500],
      });
    }
  },

  createSnackNotificationProps: function createSnackNotificationProps(snack, channelId) {
    return {
      title: `Es la hora de tu ${snackName()}`,
      body: snack.name,
      data: {},
      android: {
        channelId,
        icon: '../.././assets/images/icon.png',
      },
      ios: {
        sound: true,
      },
    };
  },

  notifyOneSnack: async function notifyOneSnack(snackFormPlan) {
    const channelId = `snack_${snackFormPlan.snack}`;

    snackFunctions.createChannelAndroid(channelId, snackFormPlan.snack);

    const notifTime = getCompleteTimeForSnack(snackFormPlan);
    if (notifTime.isBefore(moment())) {
      return null;
    }

    const snackNotification = snackFunctions.createSnackNotificationProps(snackFormPlan.snack, channelId);
    console.log(`Scheduling snack for ${notifTime.format()}`);
    const notifSchedule = await Expo.Notifications.scheduleLocalNotificationAsync(snackNotification, { time: notifTime.toDate() });
    const snackFromPlanID = snackFormPlan._id;

    return { notificationId: notifSchedule, snackFromPlanID };
  },

I am not 100% sure because testing notifications is a hell of a task, but I’m feeling that all the notifications stop triggering if I reboot the phone.

Is this possible? How do I solve it?

Thanks!


#2

Hey @alextemina,

This is the default behavior on Android unfortunately.

Cheers,

Adam


#3

Hey Adam,

Thanks for the answer.

There is no workaround?


#4

the workaround would be to use push notifications


#5

In that case I have to schedule the notifications on the server, right? I have to investigate how to do that because I have no idea…


#6

yeah you would use a server for that. sadly yes it’s more complicated, it would be great if we could extend the local notification abstraction to persist across device restarts on android


closed #7

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.