Приложение Expo запланировано сразу же запускаемые уведомления, а не запланированноеAndroid

Форум для тех, кто программирует под Android
Ответить Пред. темаСлед. тема
Anonymous
 Приложение Expo запланировано сразу же запускаемые уведомления, а не запланированное

Сообщение Anonymous »

Я построил приложение с React JS с помощью Expo. Я пытаюсь запланировать местное уведомление. Идентификатор уведомления генерируется. Но это сразу же запускается, а не запланировано. Я зарегистрировал все запланированные уведомления с использованием const pronduled = wait natifications.getAllScheduleDnotificationsAsync (); но запланированный массив возвращается []. Я звоню в эту функцию PredicleDailyNotification () после успешной регистрации. Я построил свое приложение в режиме разработчика. И все еще имею эту проблему. Кто -нибудь может помочь? < /P>
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 };



Подробнее здесь: https://stackoverflow.com/questions/794 ... ot-getting
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Android»