7

I have a flutter app where I use Firebase Cloud Messaging for notifications.

I am sending test notifications via firebase console.

Notifications function as expected on android.

On ios the notifications arrive as expected when the app is in the foreground. When the app is minimized in the background, notifications do not show in the system tray. Also no badge shows either even though a badge is set in firebase notification when I send by console.

Essentially there is no sign a notification has arrived at all until the app is opened again.

I have followed the instructions found on this page and confirmed I followed the ios integration steps to a T.

I am testing on a simulator.

Scorb
  • 1,654
  • 13
  • 70
  • 144

6 Answers6

10

As per the documentation found on Firebase website regarding apple integration:

For iOS; you must have a physical iOS device to receive messages. Firebase Cloud Messaging integrates with the Apple Push Notification service (APNs), however APNs only works with real devices.

Antonin GAVREL
  • 9,682
  • 8
  • 54
  • 81
  • Weird that the notifications arrive when the app is in the foreground though. – Scorb Feb 08 '21 at 02:52
  • It is possible that the Firebase team is working gradually to make it work on Simulator as it is quite a huge issue: I have seen countless messages of programmers encountering this problem and encountered it myself (had to borrow iphone from a friend since I don't have one). – Antonin GAVREL Feb 08 '21 at 02:57
  • What about this here ? Would this work with FCM? https://stackoverflow.com/a/60085404/9194653 – Zubeir Jun 25 '21 at 02:07
1

I have had some issues when I didn't ask for the permissions of the notifications in my App. So you should check that you have asked for the permissions of the notifications when executing the App and that it has been acepted because if you don't accept the permissions you could have problems receiving the notifications.

You can add this code in the appDelegate in the iOS project to ask for the permissions when the app executes:

let center = UNUserNotificationCenter.current()
    center.requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
        
        // Enable or disable features based on the authorization.
    }

Or you can also use a package in the pub.dev that can check and request the permissions in your App.

You can also check on the phone if the notifications are enabled for your App.

Ayad
  • 671
  • 5
  • 16
0

Follow these steps:

  1. Generate the certificates required by Apple for receiving push notifications following this guide in the Firebase docs. You can skip the section titled "Create the Provisioning Profile".

  2. Using the Firebase Console add an iOS app to your project: Follow the assistant, download the generated GoogleService-Info.plist file, open ios/Runner.xcworkspace with Xcode, and within Xcode place the file inside ios/Runner. Don't follow the steps named "Add Firebase SDK" and "Add initialization code" in the Firebase assistant.

  3. In Xcode, select Runner in the Project Navigator. In the Capabilities Tab turn on Push Notifications and Background Modes, and enable Background fetch and Remote notifications under Background Modes.

  4. Follow the steps in the "Upload your APNs certificate" section of the Firebase docs.

5.If you need to disable the method swizzling done by the FCM iOS SDK (e.g. so that you can use this plugin with other notification plugins) then add the following to your application's Info.plist file.

<key>FirebaseAppDelegateProxyEnabled</key>
<false/>

Secondly, Apple doesn't support FCM push notifications in the simulator, you have to set up a physical iOS device to run your app.

Rudresh Narwal
  • 2,740
  • 3
  • 11
  • 21
0

I had this problem recently... tried many things like this guys wrote, but the ONLY thing worked for me was change the firebase_message version to firebase_messaging: ^8.0.0-dev.14. You should try it.. there are some things that has changes from the last stable version, but the transition is not hard. You could check the tutorial here. https://firebase.flutter.dev/docs/messaging/usage/.

I saw now that they released a newest version (9.0.0).. but for me the 8.0.0 worked

*Only works in a real device

  • So are you suggesting that with that version you had system tray notifications showing on an ios simulator? – Scorb Feb 09 '21 at 17:50
  • I've updated the question. You can't do it in a simulator. You need to have a real device to test it –  Feb 09 '21 at 17:51
-1
import UIKit
import Flutter
import UserNotifications

//import FacebookCore

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
    override func application(_ application: UIApplication,didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        GeneratedPluginRegistrant.register(with: self)
       if #available(iOS 10.0, *) {
           UNUserNotificationCenter.current().delegate = self
       } else {
           // Fallback on earlier versions
       }

        //SDKApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
        return super.application(application, didFinishLaunchingWithOptions: launchOptions)
    }
    // This method will be called when app received push notifications in foreground
    
    @available(iOS 10.0, *)
    override func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)
    {
        completionHandler([.alert, .badge, .sound])
    }

}
gowthaman C
  • 472
  • 6
  • 16
-2

Make this replacement in your info.plist file .

Replace <false/> by <string>0</string>

Before :

enter image description here

Now :

enter image description here

Info : If you don't have this code in your info.plist and you don't receive the notification as well, make sure you add it.

Don't forget , here is the new code :

<key>FirebaseAppDelegateProxyEnabled</key>
<string>0</string>

Info: IOS does not support FCM push notifications in the simulator, even if you use the simulator in XCode . The best solution will be to use a physical device.

Musa Jahun
  • 66
  • 1
  • 6
Kab Agouda
  • 6,309
  • 38
  • 32