diff --git a/covas_mobile/lib/classes/notification_service.dart b/covas_mobile/lib/classes/notification_service.dart index 2b072b6..c7a6f6e 100644 --- a/covas_mobile/lib/classes/notification_service.dart +++ b/covas_mobile/lib/classes/notification_service.dart @@ -19,6 +19,28 @@ class NotificationService { ); await _notificationsPlugin.initialize(initSettings); + + // Demande les permissions au lancement + await requestPermissions(); + } + + /// Demander les permissions (Android 13+ et iOS) + static Future 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 @@ -42,24 +64,26 @@ class NotificationService { tz.TZDateTime.from(scheduledDate, tz.local), const NotificationDetails( android: AndroidNotificationDetails( - 'events_channel', // id du canal - 'Évènements', // nom du canal + 'events_channel', + 'Évènements', channelDescription: 'Notifications des évènements favoris', importance: Importance.high, priority: Priority.high, ), iOS: DarwinNotificationDetails(), ), - androidScheduleMode: AndroidScheduleMode.inexactAllowWhileIdle, + androidScheduleMode: AndroidScheduleMode + .inexactAllowWhileIdle, // évite l'erreur Exact Alarm uiLocalNotificationDateInterpretation: UILocalNotificationDateInterpretation.absoluteTime, matchDateTimeComponents: DateTimeComponents.dateAndTime, ); } + /// Notification immédiate (debug) static Future showTestNotification() async { await _notificationsPlugin.show( - 0, // id arbitraire + 0, "Test Notification", "Ceci est une notification de debug", const NotificationDetails(