Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

expo app scheduled local notification getting triggered immediately, not getting scheduled

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 };

Answer*

Draft saved
Draft discarded
Cancel

lang-js

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /