Home:ALL Converter>Show local notification when the app is opened in iOS

Show local notification when the app is opened in iOS

Ask Time:2021-08-30T14:13:33         Author:iDecode

Json Formatter

I'm using flutter_local_notifications package and it's showing notifications when the app is opened (foreground) in Android but not in the iOS. The docs says:

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.

If I understood it right, I don't need to do anything on my own except (correct me if I'm wrong and this is what the question is all about). This is the code I'm using. (Works in both iOS and Android except the foreground part)

Future<void> showNotification() async {
  final notificationPlugin = FlutterLocalNotificationsPlugin();
  const androidSettings = AndroidInitializationSettings('@mipmap/ic_launcher');
  const iOSSettings = IOSInitializationSettings();
  final initializationSettings = InitializationSettings(
    android: androidSettings,
    iOS: iOSSettings,
  );
  await notificationPlugin.initialize(
    initializationSettings,
    onSelectNotification: (payload) async {},
  );

  const androidNotificationDetails = AndroidNotificationDetails(
    'foo_id',
    'Foo Name',
    'Foo description ',
    importance: Importance.max, 
    priority: Priority.defaultPriority,
    showWhen: false,
  );

  await notificationPlugin.show(
    1211, 
    'Notification title',
    'Notification body',
    NotificationDetails(android: androidNotificationDetails),
    payload: 'item x',
  );
}

Author:iDecode,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/68979611/show-local-notification-when-the-app-is-opened-in-ios
Lala Naibova :

Add this code to your project :\nawait FirebaseMessaging.instance.setForegroundNotificationPresentationOptions(\n alert: true,\n badge: true,\n sound: true,\n );\n",
2022-03-23T20:15:11
Saifullah ilyas :

its not possible to show local notification when app is in foreground. Alternatively you can use any BannerView package or design your custom BannerView to notify the user that will gives the feel of local notification in iOS. i did not tried with flutter but i am answering this question as an iOS developer.",
2021-08-30T07:31:33
yy