-  google-services.json
- utils/notifications.ts

Fix:
- app.config.js : tambah access googleServicesFile
- app/_layout.tsx : tambah untuk push notifikasi
- package.json: install install expo-notifications expo-device expo-constants

### No Issue
This commit is contained in:
2025-11-14 17:44:22 +08:00
parent 8c3aec8e57
commit 76debfd6a6
6 changed files with 137 additions and 4 deletions

42
utils/notifications.ts Normal file
View File

@@ -0,0 +1,42 @@
// utils/notifications.ts
import * as Device from 'expo-device';
import * as Notifications from 'expo-notifications';
import Constants from 'expo-constants';
Notifications.setNotificationHandler({
handleNotification: async () => ({
shouldShowAlert: true,
shouldPlaySound: true,
shouldSetBadge: false,
shouldShowBanner: true,
shouldShowList: true,
}),
});
export async function registerForPushNotificationsAsync() {
if (!Device.isDevice) {
console.warn("Push notifications don't work on simulator");
return null;
}
const { status: existingStatus } = await Notifications.getPermissionsAsync();
let finalStatus = existingStatus;
if (existingStatus !== 'granted') {
const { status } = await Notifications.requestPermissionsAsync();
finalStatus = status;
}
if (finalStatus !== 'granted') {
console.warn('Permission not granted for push notifications');
return null;
}
const projectId = Constants?.expoConfig?.extra?.eas?.projectId;
const token = (await Notifications.getExpoPushTokenAsync({
projectId,
})).data;
console.log("Expo Push Token:", token);
return token;
}