Skip to content

[📚] firebase_messaging documentation for iOS integration needs update #3439

@stephenhuey

Description

@stephenhuey

The FCM documentation for iOS integration should come with a warning that onBackgroundMessage should not be used if the platform is iOS. This 2019 issue comment saved me from a mysterious error that was throwing an exception that did not reveal its origin in the stacktrace (see the top of that issue thread - basically it was similar to the FcmDartService#initialized one but it was #start instead).

_firebaseMessaging.configure(
        onMessage: (Map<String, dynamic> message) async {
          print("FCM onMessage: $message");
        },
        onBackgroundMessage: Platform.isIOS ? null : myBackgroundMessageHandler,
        onLaunch: (Map<String, dynamic> message) async { 
          print("FCM onLaunch: $message");
        },
        onResume: (Map<String, dynamic> message) async {
          print("FCM onResume: $message");
        },
      );

You see where I'm skipping onBackgroundMessage if it's iOS? It seems like a problem referenced in multiple issues for a long time, so I'm not sure why the documentation does not more clearly warn people that onBackgroundMessage only works for Android right now.

I deploy on both iOS and Android devices. My pubspec looks like this:


  firebase_core: "^0.5.0"
  firebase_analytics: "^6.0.0"
  firebase_auth: "^0.18.0+1"
  firebase_dynamic_links: "^0.6.0"
  cloud_firestore: "^0.14.0+2"
  cloud_functions: "^0.6.0"
  firebase_remote_config: "^0.4.0"
  firebase_messaging: "^7.0.0"

flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.17.5, on Mac OS X 10.15.4 19E287, locale en-US)

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 11.5)
[✓] Android Studio (version 3.6)
[✓] VS Code (version 1.48.0)
[!] Connected device

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions