Thomas lee
Thomas lee

Reputation: 31

iOS Notification Issue ‘Awesome Notification’ in Flutter: Notification Repeats in Foreground, Only Appears Once in Background

iOS Notification Issue ‘Awesome Notification’ in Flutter: Notification Repeats in Foreground, Only Appears Once in Background.

I want the notification to repeat every 7 seconds as I coded. On iOS, It works as expected in the foreground, but in the background, the notification only appears once and disappears. Since it’s an alarm app, I need the notification to keep repeating until the user clicks on it, even in the background. Below is the code I have written.

static void initializeNotificationListeners() {
    print('Initializing notification listeners');

    AwesomeNotifications().setListeners(
      onActionReceivedMethod: onActionReceivedMethod,
      onNotificationDisplayedMethod: onNotificationDisplayedMethod,
    );
    print('Notification listeners set');
  }



static Future<void> onNotificationDisplayedMethod(ReceivedNotification receivedNotification) async {
    
    _notificationTimer?.cancel();

    _notificationTimer = Timer.periodic(Duration(seconds: 7), (timer) async {
      int? subId = int.tryParse(receivedNotification.payload?['subId'] ?? '');

      await AwesomeNotifications().createNotification(
        content: NotificationContent(
          criticalAlert: true,
          displayOnBackground: true,
          displayOnForeground: true,
          fullScreenIntent: true,


          id: subId!, 
          channelKey: "alarm_Category",
          title: 'Alarm Reminder',
          body: 'Your alarm is still active!',
          autoDismissible: false,
          payload: receivedNotification.payload,

        ),
      );
    });
  }

Upvotes: 1

Views: 85

Answers (0)

Related Questions