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, //
shouldPlaySound: true, //
shouldSetBadge: false, //
}),
});
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',
});
}
}
//
async function requestNotificationPermission() {
const { status } = await Notifications.getPermissionsAsync();
Alert.alert("
console.log("
if (status !== 'granted') {
const { status: newStatus } = await Notifications.requestPermissionsAsync();
Alert.alert("
console.log("
if (newStatus !== 'granted') {
Alert.alert('
return false;
}
}
return true;
}
//
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, //
minute: 10,
repeats: true, //
useUTC: false,
},
});
//
const scheduled = await Notifications.getAllScheduledNotificationsAsync();
console.log("
if (scheduled.length > 0) {
Alert.alert("
} else {
Alert.alert("
}
}
export { scheduleDailyNotification };
Подробнее здесь: https://stackoverflow.com/questions/794 ... ot-getting