diff --git a/src/utils/notifications.ts b/src/utils/notifications.ts index 603db84..a172e5c 100644 --- a/src/utils/notifications.ts +++ b/src/utils/notifications.ts @@ -1,13 +1,23 @@ -import * as Notifications from 'expo-notifications'; - /** * Catatan: expo-notifications TIDAK tersedia di Expo Go (sejak SDK 53). - * Semua fungsi di sini aman (return false) supaya tidak crash — - * fitur jalan penuh saat app di-build sebagai APK (development build). + * Modul di-require secara LAZY + dibungkus try/catch supaya: + * - tidak crash di Expo Go (runtime error), + * - fitur jalan penuh saat app di-build sebagai APK. */ +async function getNotifications(): Promise { + try { + // eslint-disable-next-line @typescript-eslint/no-var-requires + return require('expo-notifications'); + } catch { + return null; + } +} + export async function ensureNotificationPermission(): Promise { try { + const Notifications = await getNotifications(); + if (!Notifications) return false; const { status } = await Notifications.getPermissionsAsync(); if (status === 'granted') return true; const req = await Notifications.requestPermissionsAsync(); @@ -22,6 +32,8 @@ export async function scheduleDailyReminder( minute: number ): Promise { try { + const Notifications = await getNotifications(); + if (!Notifications) return false; await Notifications.cancelAllScheduledNotificationsAsync(); await Notifications.scheduleNotificationAsync({ content: { @@ -42,6 +54,8 @@ export async function scheduleDailyReminder( export async function cancelReminder(): Promise { try { + const Notifications = await getNotifications(); + if (!Notifications) return false; await Notifications.cancelAllScheduledNotificationsAsync(); return true; } catch {