I am implemented Firebase Cloud Messaging for Flutter using this. all the things are working fine in Android, but iOS push notification only show when app is in foreground.
Please help me for show notification app in background and terminated.
Those are the steps I done so far
- Created firbase project.
- Add GoogleService-Info.plist to xcode.
- Add firebase_messaging: ^6.0.13 & flutter_local_notifications: ^1.3.0 into pubspec.yaml.
In flutter
FirebaseMessaging firebaseMessaging = new FirebaseMessaging(); FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin(); @override void initState() { super.initState(); var android = new AndroidInitializationSettings('mipmap/ic_launcher'); var ios = new IOSInitializationSettings(); var platform = new InitializationSettings(android, ios); flutterLocalNotificationsPlugin.initialize(platform); firebaseMessaging.configure( onLaunch: (Map<String, dynamic> msg) async{ print(" onLaunch called ${(msg)}"); }, onResume: (Map<String, dynamic> msg) async{ print(" onResume called ${(msg)}"); }, onMessage: (Map<String, dynamic> msg) async{ showNotification(msg); print(" onMessage called ${(msg)}"); }, ); firebaseMessaging.requestNotificationPermissions( const IosNotificationSettings(sound: true, alert: true, badge: true)); firebaseMessaging.onIosSettingsRegistered .listen((IosNotificationSettings setting) { print('IOS Setting Registed'); }); firebaseMessaging.getToken().then((token) { update(token); }); getCashedInfo(); } showNotification(Map<String, dynamic> msg) async { var android = new AndroidNotificationDetails( 'sdffds dsffds', "CHANNLE NAME", "channelDescription", ); var iOS = new IOSNotificationDetails(); var platform = new NotificationDetails(android, iOS); await flutterLocalNotificationsPlugin.show( 0, "This is title", "this is demo", platform); } update(String token) { print(token); }
In Xcode I added
if #available(iOS 10.0, *) { UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate }