Skip to content

[IOS] Notification not shown when the app is in foreground state #2196

@ariona

Description

@ariona

Describe the bug

Notification did not shown when the app is in foreground state on IOS

To Reproduce
Here is the code i use, i am setting all present option to true, but the notification did not show up. it's only showing up when the app is minimized.

await flutterLocalNotificationsPlugin.show(
  99,
  'title'
  'notification body',
  NotificationDetails(
    android: AndroidNotificationDetails(),
    iOS: DarwinNotificationDetails(
        sound: "adzan.aiff",
        interruptionLevel: InterruptionLevel.timeSensitive,
        presentSound: true,
        presentList: true,
        presentAlert: true,
        presentBadge: true,
        presentBanner: true,
     )
  ),
);

Expected behavior

As stated on readme, default behavior for IOS is to show notification even on foreground. But even after setting the presentation option to true it didn't show up.

For iOS 10+, use the presentation options to control the behaviour for when a notification is triggered while the app is in the foreground. The default settings of the plugin will configure these such that a notification will be displayed when the app is in the foreground.

Sample code to reproduce the problem

/// initialization part
final InitializationSettings initializationSettings = InitializationSettings(,
  iOS: DarwinInitializationSettings(
    defaultPresentAlert: true,
    defaultPresentBadge: true,
    defaultPresentBanner: true,
    defaultPresentSound: true,
    onDidReceiveLocalNotification: (int id, String? title, String? body, String? payload){
      print([id, title, body, payload]);
    },
    defaultPresentList: true
  )
);
await flutterLocalNotificationsPlugin.initialize(
  initializationSettings,
  onDidReceiveNotificationResponse: (response){
    print(["onDidReceiveNotificationResponse", response.actionId]);
  },
  onDidReceiveBackgroundNotificationResponse: notificationTapBackground,
);


/// Calling notification part
await flutterLocalNotificationsPlugin.show(
  99,
  'title'
  'notification body',
  NotificationDetails(
    android: AndroidNotificationDetails(),
    iOS: DarwinNotificationDetails(
        sound: "adzan.aiff",
        interruptionLevel: InterruptionLevel.timeSensitive,
        presentSound: true,
        presentList: true,
        presentAlert: true,
        presentBadge: true,
        presentBanner: true,
     )
  ),
);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions