Flutter local notification doesn t work for iOS

0 votes

Hello flutter newbie here! I'm using flutter local notifications and adding the default code to my app. It works in Android but doesn't work in iOS. any idea why?

I tried with both the iOS simulator for iPhone 8 and iPhone 11. It works on my android emulator which is a Pixel 3 API 29.

I have also enabled the Notifications in iOS (Settings>this app>Notifications) for this app and gave the permissions.

For Android I have added permission requests in AndroidManifest.xml.

import 'package:flutter/material.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';


class AppNotification extends StatefulWidget {
  static const String id = 'app_notification';

  @override
  _AppNotificationState createState() => _AppNotificationState();
}

class _AppNotificationState extends State<AppNotification> {
  FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin;

  @override
  void initState() {
    super.initState();
    flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
    var android = AndroidInitializationSettings('app_icon');
    var iOS = IOSInitializationSettings();
    var initSettings = InitializationSettings(android, iOS);

    flutterLocalNotificationsPlugin.initialize(initSettings,
        onSelectNotification: onSelectNotification);
  }

  Future onSelectNotification(String payload) async {
    debugPrint("payload : $payload");
    showDialog(
      context: context,
      builder: (_) {
        return AlertDialog(
          title: Text("PayLoad"),
          content: Text("Payload : $payload"),
        );
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            FlatButton(
              child: Text('Notification'),
              onPressed: _showNotificationWithDefaultSound,
            ),
            FlatButton(
              onPressed: () {
                Navigator.pop(context);
              },
              child: Text('back'),
            )
          ],
        ),
      ),
    );
  }

  // TODO iOS doesn't work

  Future _showNotificationWithDefaultSound() async {
    var androidPlatformChannelSpecifics = new AndroidNotificationDetails(
        'your channel id', 'your channel name', 'your channel description',
        importance: Importance.Max, priority: Priority.High);
    var iOSPlatformChannelSpecifics = new IOSNotificationDetails();
    var platformChannelSpecifics = new NotificationDetails(
        androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
    await flutterLocalNotificationsPlugin.show(
      0,
      'New Post',
      'How to Show Notification in Flutter',
      platformChannelSpecifics,
      payload: 'Default_Sound',
    );
  }


 

Sep 21 in Others by gaurav
• 22,040 points
459 views

1 answer to this question.

0 votes

I added This line in the "AppDelegate.swift" inside didFinishLaunchingWithOptions method and it solved my issue:

if #available(iOS 10.0, *) {
    UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
}
answered Sep 21 by rajatha
• 7,480 points

Related Questions In Others

0 votes
1 answer

How to set margin for a Container in Flutter?

Hi@akhtar, Margin property is used to set empty ...READ MORE

answered Jul 29, 2020 in Others by MD
• 95,380 points
4,769 views
0 votes
1 answer

How to use for loop in Flutter?

Hi@akhtar, As the name suggests Dart for in ...READ MORE

answered Sep 3, 2020 in Others by MD
• 95,380 points
16,922 views
0 votes
0 answers

Custom URL scheme for Pinterest on iOS Safari to open board URL?

I can't for the life of me ...READ MORE

Sep 23 in Others by gaurav
• 22,040 points
49 views
0 votes
1 answer

What is the future of flutter?

Hi@MD, Flutter is a rather new cross-platform framework ...READ MORE

answered Jul 17, 2020 in Others by akhtar
• 38,240 points
471 views
0 votes
1 answer

What is Flutter?

Hi@akhtar, Flutter is an app SDK for building ...READ MORE

answered Jul 17, 2020 in Others by MD
• 95,380 points
626 views
0 votes
1 answer

ios: localize emoji name (kCFStringTransformToUnicodeName)

There is no api for this job. Unicode ...READ MORE

answered Sep 21 in Others by rajatha
• 7,480 points
70 views
0 votes
1 answer

iOS Keyboard Extension: Memoji like paste

All the mentioned apps use UITextView, upon ...READ MORE

answered Sep 21 in Others by rajatha
• 7,480 points
76 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP