skip to Main Content

Notifications are working properly on Android but not working at all on iOS (tried on emulator).
I have the code in the main page and the notification doesn’t show.
Please note that I already made changes on AppDelegate.swift file.

FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();

flutterLocalNotificationsPlugin
        .resolvePlatformSpecificImplementation<
            AndroidFlutterLocalNotificationsPlugin>()!
        .requestPermission();

    const AndroidInitializationSettings initializationSettingsAndroid = AndroidInitializationSettings('icon');

    final DarwinInitializationSettings initializationSettingsDarwin =
        DarwinInitializationSettings(
            requestSoundPermission: true,
            requestBadgePermission: true,
            requestAlertPermission: true,
            onDidReceiveLocalNotification: onDidReceiveLocalNotification);

    final InitializationSettings initializationSettings =
        InitializationSettings(
            android: initializationSettingsAndroid,
            iOS: initializationSettingsDarwin,
            macOS: initializationSettingsDarwin);

    await flutterLocalNotificationsPlugin.initialize(initializationSettings, onDidReceiveNotificationResponse:  onDidReceiveNotificationResponse);

    const AndroidNotificationDetails androidNotificationDetails =
        AndroidNotificationDetails('can1', 'Channel 1',
            channelDescription: "Desc here",
            importance: Importance.max,
            priority: Priority.high,
            ticker: 'ticker');

    const NotificationDetails notificationDetails =
        NotificationDetails(android: androidNotificationDetails);

    await flutterLocalNotificationsPlugin.show(
        0, 'Notification is working!', 'Hello world', notificationDetails, payload: 'item x');

2

Answers


  1. It’s happened to me before but different issue (updates problems) on android and finally found that’s

    1. run command ‘flutter upgrade’.
    2. run command ‘flutter clean’.
    3. update to the last package version in pubspec.yaml.
    4. delete the IOS folder and then run command ‘flutter create .’.
    5. now follow the package docs steps.
    Login or Signup to reply.
  2. Notification doesnt work in ios emulator, you need to use real device

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search