feature/notification-date #49
@@ -19,6 +19,28 @@ class NotificationService {
|
|||||||
);
|
);
|
||||||
|
|
||||||
await _notificationsPlugin.initialize(initSettings);
|
await _notificationsPlugin.initialize(initSettings);
|
||||||
|
|
||||||
|
// Demande les permissions au lancement
|
||||||
|
await requestPermissions();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Demander les permissions (Android 13+ et iOS)
|
||||||
|
static Future<void> requestPermissions() async {
|
||||||
|
// Android 13+
|
||||||
|
final androidImplementation =
|
||||||
|
_notificationsPlugin.resolvePlatformSpecificImplementation<
|
||||||
|
AndroidFlutterLocalNotificationsPlugin>();
|
||||||
|
await androidImplementation?.requestNotificationsPermission();
|
||||||
|
|
||||||
|
// iOS
|
||||||
|
final iosImplementation =
|
||||||
|
_notificationsPlugin.resolvePlatformSpecificImplementation<
|
||||||
|
IOSFlutterLocalNotificationsPlugin>();
|
||||||
|
await iosImplementation?.requestPermissions(
|
||||||
|
alert: true,
|
||||||
|
badge: true,
|
||||||
|
sound: true,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Planifie une notification 1h avant l’évènement
|
/// Planifie une notification 1h avant l’évènement
|
||||||
@@ -42,24 +64,26 @@ class NotificationService {
|
|||||||
tz.TZDateTime.from(scheduledDate, tz.local),
|
tz.TZDateTime.from(scheduledDate, tz.local),
|
||||||
const NotificationDetails(
|
const NotificationDetails(
|
||||||
android: AndroidNotificationDetails(
|
android: AndroidNotificationDetails(
|
||||||
'events_channel', // id du canal
|
'events_channel',
|
||||||
'Évènements', // nom du canal
|
'Évènements',
|
||||||
channelDescription: 'Notifications des évènements favoris',
|
channelDescription: 'Notifications des évènements favoris',
|
||||||
importance: Importance.high,
|
importance: Importance.high,
|
||||||
priority: Priority.high,
|
priority: Priority.high,
|
||||||
),
|
),
|
||||||
iOS: DarwinNotificationDetails(),
|
iOS: DarwinNotificationDetails(),
|
||||||
),
|
),
|
||||||
androidScheduleMode: AndroidScheduleMode.inexactAllowWhileIdle,
|
androidScheduleMode: AndroidScheduleMode
|
||||||
|
.inexactAllowWhileIdle, // évite l'erreur Exact Alarm
|
||||||
uiLocalNotificationDateInterpretation:
|
uiLocalNotificationDateInterpretation:
|
||||||
UILocalNotificationDateInterpretation.absoluteTime,
|
UILocalNotificationDateInterpretation.absoluteTime,
|
||||||
matchDateTimeComponents: DateTimeComponents.dateAndTime,
|
matchDateTimeComponents: DateTimeComponents.dateAndTime,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Notification immédiate (debug)
|
||||||
static Future<void> showTestNotification() async {
|
static Future<void> showTestNotification() async {
|
||||||
await _notificationsPlugin.show(
|
await _notificationsPlugin.show(
|
||||||
0, // id arbitraire
|
0,
|
||||||
"Test Notification",
|
"Test Notification",
|
||||||
"Ceci est une notification de debug",
|
"Ceci est une notification de debug",
|
||||||
const NotificationDetails(
|
const NotificationDetails(
|
||||||
|
Reference in New Issue
Block a user