Files
asle/mobile/src/services/notifications.ts

53 lines
1.3 KiB
TypeScript
Raw Normal View History

import PushNotification from 'react-native-push-notification';
export class NotificationService {
static initialize() {
PushNotification.configure({
onRegister: function (token) {
console.log('TOKEN:', token);
},
onNotification: function (notification) {
console.log('NOTIFICATION:', notification);
},
permissions: {
alert: true,
badge: true,
sound: true,
},
popInitialNotification: true,
requestPermissions: true,
});
PushNotification.createChannel(
{
channelId: 'asle-default',
channelName: 'ASLE Notifications',
channelDescription: 'Notifications for ASLE platform',
playSound: true,
soundName: 'default',
importance: 4,
vibrate: true,
},
(created) => console.log(`Channel created: ${created}`)
);
}
static scheduleLocalNotification(title: string, message: string, date: Date) {
PushNotification.localNotificationSchedule({
channelId: 'asle-default',
title,
message,
date,
});
}
static sendLocalNotification(title: string, message: string) {
PushNotification.localNotification({
channelId: 'asle-default',
title,
message,
});
}
}