Kantongku: amankan notifikasi untuk Expo Go (aktif penuh di APK)
This commit is contained in:
@@ -122,12 +122,19 @@ export function SettingsScreen() {
|
||||
const ok = await ensureNotificationPermission();
|
||||
if (!ok) {
|
||||
Alert.alert(
|
||||
'Izin notifikasi ditolak',
|
||||
'Aktifkan izin notifikasi di pengaturan HP untuk memakai pengingat.'
|
||||
'Notifikasi belum tersedia di Expo Go',
|
||||
'Fitur pengingat akan aktif saat app di-build sebagai APK. (Expo Go tidak mendukung notifikasi sejak SDK 53)'
|
||||
);
|
||||
return;
|
||||
}
|
||||
const scheduled = await scheduleDailyReminder(reminderHour, 0);
|
||||
if (!scheduled) {
|
||||
Alert.alert(
|
||||
'Gagal menjadwalkan',
|
||||
'Notifikasi belum tersedia di Expo Go — akan aktif di versi APK.'
|
||||
);
|
||||
return;
|
||||
}
|
||||
await scheduleDailyReminder(reminderHour, 0);
|
||||
await setSetting('reminder_enabled', '1');
|
||||
await setSetting('reminder_hour', String(reminderHour));
|
||||
setReminderEnabled(true);
|
||||
@@ -142,7 +149,15 @@ export function SettingsScreen() {
|
||||
setReminderHour(hour);
|
||||
await setSetting('reminder_hour', String(hour));
|
||||
if (reminderEnabled) {
|
||||
await scheduleDailyReminder(hour, 0);
|
||||
const scheduled = await scheduleDailyReminder(hour, 0);
|
||||
if (!scheduled) {
|
||||
setReminderEnabled(false);
|
||||
await setSetting('reminder_enabled', '0');
|
||||
Alert.alert(
|
||||
'Gagal menjadwalkan',
|
||||
'Notifikasi belum tersedia di Expo Go — akan aktif di versi APK.'
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
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).
|
||||
*/
|
||||
|
||||
export async function ensureNotificationPermission(): Promise<boolean> {
|
||||
try {
|
||||
const { status } = await Notifications.getPermissionsAsync();
|
||||
@@ -14,7 +20,8 @@ export async function ensureNotificationPermission(): Promise<boolean> {
|
||||
export async function scheduleDailyReminder(
|
||||
hour: number,
|
||||
minute: number
|
||||
): Promise<void> {
|
||||
): Promise<boolean> {
|
||||
try {
|
||||
await Notifications.cancelAllScheduledNotificationsAsync();
|
||||
await Notifications.scheduleNotificationAsync({
|
||||
content: {
|
||||
@@ -27,8 +34,17 @@ export async function scheduleDailyReminder(
|
||||
minute,
|
||||
},
|
||||
});
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export async function cancelReminder(): Promise<void> {
|
||||
export async function cancelReminder(): Promise<boolean> {
|
||||
try {
|
||||
await Notifications.cancelAllScheduledNotificationsAsync();
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user