I am using flutter local_notification plugin to schedule some notifications a day using zonedSchedule method for 4 days. I have implemented this plugin as per documentation and my notifications are showing at first, however after some time my app skips a notification and then shows next one and then it completely stops showing notifications. I have even implemented time sensitive notification bit it stills does this. I have re-check my logic for scheduling notification and it seems fine if anyone have any idea for why this is behaving like this please do help thanks. following is some part of my code:
Note: same app is working fine on Android and showing all notifications.
Initialising Notification:
final StreamController<ReceivedNotification>
didReceiveLocalNotificationStream =
StreamController<ReceivedNotification>.broadcast();
final StreamController<String?> selectNotificationStream =
StreamController<String?>.broadcast();
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();
final AndroidInitializationSettings initializationSettingsAndroid =
const AndroidInitializationSettings('launcher_icon');
Future<void> init({bool permission = true}) async {
await _configureLocalTimeZone();
final DarwinInitializationSettings initializationSettingsDarwin =
DarwinInitializationSettings(
requestAlertPermission: permission,
requestBadgePermission: permission,
requestSoundPermission: permission,
onDidReceiveLocalNotification:
(int id, String? title, String? body, String? payload) async {
didReceiveLocalNotificationStream.add(
ReceivedNotification(
id: id,
title: title,
body: body,
payload: payload,
),
);
},
notificationCategories: const [
DarwinNotificationCategory('plainCategory')
],
);
// initialization
final InitializationSettings initializationSettings =
InitializationSettings(
android: initializationSettingsAndroid,
iOS: initializationSettingsDarwin);
await flutterLocalNotificationsPlugin.initialize(
initializationSettings,
onDidReceiveNotificationResponse:
(NotificationResponse notificationResponse) {
switch (notificationResponse.notificationResponseType) {
case NotificationResponseType.selectedNotification:
selectNotificationStream.add(notificationResponse.payload);
break;
case NotificationResponseType.selectedNotificationAction:
print("Tap on notificaion action:${notificationResponse.actionId}");
// if (notificationResponse.actionId == navigationActionId) {
// selectNotificationStream.add(notificationResponse.payload);
// }
break;
}
},
onDidReceiveBackgroundNotificationResponse: notificationTapBackground,
);
}
Zoned Scheduling Notification:
Future<void> zonedScheduleNotification(int id, String title, String message,
tz.TZDateTime scheduleDateTime, String key,
{int audioId = 1, bool notificationSound = false}) async {
// final audioId = await Store.getAudioId(key);
final selectedAudio = audios.firstWhere((it) => it.id == audioId);
final channelId =
notificationSound ? selectedAudio.name : "def.cc";
await flutterLocalNotificationsPlugin.zonedSchedule(
id,
title,
message,
scheduleDateTime, //tz.TZDateTime.now(tz.local).add(const Duration(seconds: 5)),
NotificationDetails(
android: AndroidNotificationDetails(
channelId, channelId,
channelDescription: channelId,
// timeoutAfter: const Duration(hours: 1)
// .inMilliseconds, // dismiss notification after 1 hour
sound: notificationSound
? RawResourceAndroidNotificationSound(selectedAudio.name)
: null,
styleInformation: const BigTextStyleInformation(''),
importance: Importance.max,
priority: Priority.high
),
iOS: notificationSound
? DarwinNotificationDetails(presentSound: true, sound: selectedAudio.iosname, interruptionLevel: InterruptionLevel.timeSensitive)
: const DarwinNotificationDetails(presentSound: true, interruptionLevel: InterruptionLevel.timeSensitive),
),
androidAllowWhileIdle: true,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime);
}
Things I have tried: Checked logic of scheduling notification. Implemented time sensitive notification for IOS. Follows documentation to setup local_notification plugin