Ask Your Question
1

How can I set up an Expo notification to be scheduled every day except for Saturdays and Sundays?

asked 2022-08-11 11:00:00 +0000

ladyg gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-08-25 08:00:00 +0000

djk gravatar image

To set up an Expo notification to be scheduled every day except for Saturdays and Sundays, you can use the Notifications.scheduleNotificationAsync() function with the weekdays option.

Here is some sample code that demonstrates how to set up an Expo notification to repeat every day except for Saturdays and Sundays:

import { Notifications } from 'expo';
import * as Permissions from 'expo-permissions';

// Request permission to send notifications
const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);

// Check if permission was granted
if (status !== 'granted') {
  return;
}

// Set up notification settings
const notificationContent = {
  title: 'Daily Reminder',
  body: 'Don\'t forget to do something important!',
};

// Schedule notification for weekdays only
Notifications.scheduleNotificationAsync({
  content: notificationContent,
  trigger: {
    hour: 9,
    minute: 0,
    repeats: true,
    weekdays: [1, 2, 3, 4, 5], // Monday = 1, Tuesday = 2, ..., Friday = 5
  },
});

In this example, the notification is scheduled to trigger every day at 9:00 AM, but only on weekdays (Monday to Friday). The weekdays option specifies an array of integers representing the days of the week on which the notification should repeat. Saturday is represented by 6 and Sunday is represented by 0, so they are excluded from the array.

Note that this example assumes that the code is being run within an Expo app, and that the necessary permissions have been obtained beforehand using the Permissions module. You may need to customize this code to suit your specific use case.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-08-11 11:00:00 +0000

Seen: 11 times

Last updated: Aug 25 '22