Skip to content
Tutorials Center
My learning

Topics

Lesson 26 of 38 ยท Notifications and Background Tasks

Scheduling Local Notifications

Schedule reminders in Expo with expo-notifications: time-interval, daily, weekly and date triggers, cancelling, badges, categories with action buttons and Android channels.

Not every notification needs a server. A habit tracker reminds you at 8 pm, a timer rings in 25 minutes, a calendar warns you before a meeting. These are local notifications: your app tells the operating system "show this at that time", and the OS delivers it even if the app is closed. No network, no push token, no backend.

This is also the easiest way to learn expo-notifications, because you can test it without any credentials in a development build.

What runs on this site. The notification scheduler lives in the OS, so the real calls are read-only. The runnable stand-ins compute the same trigger times (next daily or weekly occurrence, repeat intervals) in plain Node.js, which is the date logic you will actually have to get right.

Your first scheduled notification

JSX
import * as Notifications from 'expo-notifications';

const id = await Notifications.scheduleNotificationAsync({
  content: {
    title: 'Time to stretch',
    body: 'Stand up for two minutes.',
    data: { screen: 'timer' },
    sound: true,
  },
  trigger: {
    type: Notifications.SchedulableTriggerInputTypes.TIME_INTERVAL,
    seconds: 60 * 25,
  },
});

scheduleNotificationAsync returns an identifier. Keep it if you may want to cancel the reminder later. Permission works exactly as in the push lesson: check with getPermissionsAsync, then requestPermissionsAsync.

Trigger types

Trigger type Fires Example fields
TIME_INTERVAL after N seconds, optionally repeating seconds: 3600, repeats: true
DATE once at an exact date date: new Date(...)
DAILY every day at a time hour: 20, minute: 0
WEEKLY every week weekday: 2, hour: 9, minute: 30
MONTHLY, YEARLY by day of month or date day: 1, hour: 8, minute: 0
CALENDAR iOS calendar match { hour, minute, repeats }

Notes worth remembering:

  • weekday runs from 1 (Sunday) to 7 (Saturday).
  • A repeating TIME_INTERVAL needs at least 60 seconds.
  • iOS keeps only the 64 soonest local notifications. If you schedule more, the rest are dropped, so schedule a rolling window instead of a year at once.
  • On Android, an exact-time alarm may need extra permission on newer versions; inexact timing is fine for most reminders.

The date logic

OS triggers such as DAILY handle the repeat for you. But often you want a one-time DATE trigger computed from user input ("remind me every weekday at 7:30"). That date calculation is plain JavaScript, and bugs hide in it (past times, month ends, time zones).

Node.js Next occurrence calculator

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

The result of Friday evening is Monday morning: the weekend is skipped. Dates are built in the device's local time zone, which is what a reminder should use.

Listing and cancelling

JSX
const all = await Notifications.getAllScheduledNotificationsAsync();
await Notifications.cancelScheduledNotificationAsync(id);   // one
await Notifications.cancelAllScheduledNotificationsAsync(); // all

A common pattern for "edit reminder": cancel the old id, schedule a new one, store the new id next to your data. Another is a deterministic id: pass identifier: 'daily-water' to scheduleNotificationAsync. Scheduling again with the same identifier replaces the old one, so you cannot create duplicates by accident.

Node.js Scheduler with replace-by-identifier

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Content options

JSX
content: {
  title: 'Meeting in 10 minutes',
  subtitle: 'Design review',     // iOS
  body: 'Room 4B',
  data: { eventId: 17 },         // delivered back to your code on tap
  badge: 1,                      // app icon number
  sound: 'default',
  categoryIdentifier: 'reminder',// action buttons, see below
  interruptionLevel: 'timeSensitive', // iOS
}

Set the badge directly with Notifications.setBadgeCountAsync(0). Clear it when the user opens the app.

Action buttons

A category attaches buttons such as "Snooze" and "Done" to a notification:

JSX
await Notifications.setNotificationCategoryAsync('reminder', [
  { identifier: 'snooze', buttonTitle: 'Snooze 10 min' },
  { identifier: 'done', buttonTitle: 'Done', options: { opensAppToForeground: false } },
]);

The button the user pressed arrives in the response listener as response.actionIdentifier. You decide what to do: for snooze, schedule the same content again 600 seconds from now.

Android channels

On Android 8+, every notification belongs to a channel, and the user controls each channel in system settings (sound, importance, vibration). Create channels for your categories of messages, and never change a channel's importance in code later; users own that setting after creation.

JSX
await Notifications.setNotificationChannelAsync('reminders', {
  name: 'Reminders',
  importance: Notifications.AndroidImportance.HIGH,
  vibrationPattern: [0, 250, 250, 250],
});
// then: trigger: { type: ..., channelId: 'reminders', ... }

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does scheduleNotificationAsync return?

    The identifier lets you cancel or replace that scheduled notification.
  2. 2. What happens if you schedule twice with the same identifier?

    Using the same identifier replaces the existing scheduled notification.
  3. 3. What is the iOS limit for scheduled local notifications?

    iOS keeps only the 64 soonest, so schedule a rolling window.
  4. 4. In an Expo weekly trigger, which number is Sunday?

    weekday goes from 1 (Sunday) to 7 (Saturday), unlike JavaScript's getDay where Sunday is 0.

Summary

  • Local notifications need no server: the OS delivers them on schedule, even when the app is closed.
  • Pick a trigger: time interval, exact date, daily, weekly and so on.
  • Use stable identifiers to replace reminders, and cancel by id.
  • Remember the 64-notification iOS limit and Android channels.
  • Categories add action buttons; read actionIdentifier in the response listener.

Next: Background tasks