Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Firebase Messaging Not working on IOS when app running in background or closed

I have configured firebase Cloud Messaging with flutter Notification are working in foreground. but not working when running in background or app is killed.

Following steps are done.

  • Generated app ID and push Key in https://developer.apple.com/account/resources/certificates/
  • Added info.plist to ios/Runner folder
  • Turned on Push capabilities
  • Uploaded APNS certificate to Firebase console
  • Added lines in AppDelegate.swift

Also tried to remove following line as suggested on Flutter Firebase Cloud Messaging - Notification when app in background but it is still not working.

if (@available(iOS 10.0, *)) { [UNUserNotificationCenter currentNotificationCenter].delegate = (id) self; }

Flutter Doctor  [✓] Flutter (Channel beta, v1.12.13+hotfix.6, on Mac OS X 10.14.5 18F132, locale en-IN)  [✗] Android toolchain - develop for Android devices      ✗ Unable to locate Android SDK.        Install Android Studio from: https://developer.android.com/studio/index.html        On first launch it will assist you in installing the Android SDK components.        (or visit https://flutter.dev/setup/#android-setup for detailed instructions).        If the Android SDK has been installed to a custom location, set ANDROID_HOME to that location.        You may also want to add it to your PATH environment variable.    [✓] Xcode - develop for iOS and macOS (Xcode 11.3)  [✓] Chrome - develop for the web  [!] Android Studio (not installed)  [✓] Connected device (3 available) 

One thing I noticed that , when app is installed first time it is not asking me to check if the I allow the app to send push notification.

My code is having following lines on page after login page.

_firebaseMessaging.requestNotificationPermissions(         const IosNotificationSettings(sound: true, badge: true, alert: true));     _firebaseMessaging.onIosSettingsRegistered         .listen((IosNotificationSettings settings) {       print("Settings registered: $settings");     }); 

Also cross checked that all following setting are ticked.

enter image description here

like image 803
max Avatar asked Feb 22 '20 08:02

max


People also ask

How do you handle background notifications in Flutter?

It offers a bunch of features like for example scheduling when notifications should appear, periodically show a notification (interval-based), handle when a user has tapped on a notification when the app is in the foreground, background, or terminated, specify a custom notification sound and much more.

What is FlutterFire?

FlutterFire is a set of Flutter plugins which connect your Flutter application to Firebase.


Video Answer


1 Answers

After a long time searching for a fix, this solved the problem for me:

  1. In your info.plist:

     FirebaseAppDelegateProxyEnabled: false 
  2. Add this to your AppDelegate:

    override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {     Messaging.messaging().apnsToken = deviceToken    super.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)  } 
like image 180
dcg Avatar answered Sep 17 '22 22:09

dcg