3

I have built an app with react js using expo. I am trying to schedule a local notification. The notification ID is getting generated. But it is triggered immediately, not being scheduled. I logged all the scheduled notifications using const scheduled = await Notifications.getAllScheduledNotificationsAsync();but the scheduled array is returning []. I am calling this scheduleDailyNotification() function after successful signup. I have built my app in developer mode. And still having this problem. Can anyone help?

import * as Notifications from 'expo-notifications';
import { Alert, Platform } from 'react-native';
import Constants from "expo-constants";
import * as Device from 'expo-device';
Notifications.setNotificationHandler({
 handleNotification: async () => ({
 shouldShowAlert: true, // βœ… Ensures the notification is displayed
 shouldPlaySound: true, // βœ… Enables sound
 shouldSetBadge: false, // ❌ No badge update
 }),
});
async function createNotificationChannel() {
 if (Platform.OS === 'android') {
 await Notifications.setNotificationChannelAsync('default', {
 name: 'Default Channel',
 importance: Notifications.AndroidImportance.MAX,
 vibrationPattern: [0, 250, 250, 250],
 lightColor: '#FF231F7C',
 });
 }
}
// βœ… Request Notification Permission and return boolean status
async function requestNotificationPermission() {
 const { status } = await Notifications.getPermissionsAsync();
 Alert.alert("πŸ” Initial Permission Status", status); // βœ… Show initial permission status
 console.log("πŸ” Initial Permission Status", status);
 if (status !== 'granted') {
 const { status: newStatus } = await Notifications.requestPermissionsAsync();
 Alert.alert("πŸ“’ New Permission Status", newStatus); // βœ… Show new permission status
 console.log("πŸ“’ New Permission Status", newStatus);
 if (newStatus !== 'granted') {
 Alert.alert('❌ Permission Denied', 'Notifications are disabled.');
 return false;
 }
 }
 
 return true;
}
// βœ… Schedule Daily Notification
async function scheduleDailyNotification() {
 await createNotificationChannel();
 await Notifications.cancelAllScheduledNotificationsAsync(); // Clears old schedules to prevent duplicates
 await Notifications.scheduleNotificationAsync({
 content: {
 title: "Daily Reminder",
 body: "It is a scheduled notification!",
 sound: "default",
 priority: Notifications.AndroidNotificationPriority.MAX,
 },
 trigger: {
 hour: 20, // βœ… 8:10 PM (24-hour format)
 minute: 10,
 repeats: true, // πŸ”„ Repeat every day
 useUTC: false,
 },
 });
 // βœ… Fetch all scheduled notifications to verify it's scheduled
 const scheduled = await Notifications.getAllScheduledNotificationsAsync();
 console.log("πŸ“… Scheduled Notifications:", scheduled);
 if (scheduled.length > 0) {
 Alert.alert("βœ… Notification Scheduled", `Next reminder at 3:00 PM`);
 } else {
 Alert.alert("❌ No Notifications Scheduled", "Something went wrong.");
 }
}
export { scheduleDailyNotification };
asked Feb 3, 2025 at 2:12
2
  • I am having the same issue, how did you fix this? Commented Jun 16, 2025 at 1:03
  • did you find the solution yet? Commented Aug 22, 2025 at 0:47

2 Answers 2

1

Try the above code mentioned by Mohammad, if the array is not empty and you are still facing the same issue as in the issue of it not scheduling the notification then you should define the type of the notification - In my application I'm using a date that is calculated from an API and so i use type: Notifications.SchedulableTriggerInputTypes.DATE in my scheduleNotificationAsync function then inside that function trigger then type - Please note there are multiple types of notification schedulable triggers so you should experiment to see which one best fits your needs.

Dharman
34k27 gold badges106 silver badges158 bronze badges
answered Feb 7, 2025 at 20:00
Sign up to request clarification or add additional context in comments.

Comments

1

In the trigger, you need to specify the trigger type:

await Notifications.scheduleNotificationAsync({
 content: {
 title: "Daily Reminder",
 body: "It is a scheduled notification!",
 sound: "default",
 priority: Notifications.AndroidNotificationPriority.MAX,
 },
 trigger: {
 hour: 20, // βœ… 8:10 PM (24-hour format)
 minute: 10,
 repeats: true, // πŸ”„ Repeat every day
 useUTC: false,
 type: SchedulableTriggerInputTypes.DAILY, // ***NEED THIS HERE***
 },
 });

https://docs.expo.dev/versions/latest/sdk/notifications/#dailytriggerinput

answered Sep 18, 2025 at 18:56

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.