firebase / flutterfire

🔥 A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.51k stars 3.92k forks source link

[firebase_messaging] onBackgroundMessage is not called when a lot of notifications come in after killing the app [IOS-Android] #9549

Closed baraaaljabban closed 1 year ago

baraaaljabban commented 1 year ago

Bug report

Describe the bug the method of onBackgroundMessage is not being called when the server sends for example from 15 to 30 notifications after the app is killed, in this case you will see all the notifications in the tray, but onBackgroundMessage will not be triggered for each one of the notifications. for example the server sends 30 notifications in a raw with the messages from [1-30], and onBackgroundMessage you will be called for [1,4,6...30] so 2,3,5 will not be handled but you still can see it in the tray of the mobile (this is for example you might miss other numbers but most likely it will be from the first 10 notifications). this is happening for both IOS and Android

Steps to reproduce

Steps to reproduce the behavior:

  1. kill the app and wait for about 3 minutes.
  2. send about 15 to 30 notifications from your script or server to your mobile.
  3. you can see all the notifications in the tray of the mobile phone
  4. add some logic in your onBackgroundMessage and check if can handle all of the notifications
  5. for testing try to report to crashlytics ( inside onBackgroundMessage) and then check if you can see all the notifications are handled or not. ( you can try to save it locally and see the result as well)
  6. you will see that some notifications are missing and reset are reported to crashlytics

Expected behavior

all the notifications that come to the app should be handled if you send 15 then the 15 one should be handled

Sample project

Future<void> mainCommon(AppEnvironment env) async {
  WidgetsFlutterBinding.ensureInitialized();
  Isolate.current.addErrorListener(
    RawReceivePort(
      (pair) async {
        final List<dynamic> errorAndStacktrace = pair;
        await _reportError(errorAndStacktrace.first, errorAndStacktrace.last);
      },
    ).sendPort,
  );

  await Firebase.initializeApp();
  FirebaseMessaging.onBackgroundMessage(onBackgroundMessage);
  await slInit();
  // rest of the code .......
}

Future<void> onBackgroundMessage(RemoteMessage message) async {
  await Firebase.initializeApp();
  FirebaseCrashlytics.instance.recordError(message, null);
}

Additional context

in my case I was saving the niotfications in the localDB then when I noticied that some notificaitons are missing

Future<void> onBackgroundMessage(RemoteMessage message) async {
  await Firebase.initializeApp();
  late NotificationService _service;

  try {
    _service = sl<NotificationService>();
  } catch (e) {
    await sl.reset();
    await slInit();
    _service = sl<NotificationService>();
  }
  //save notifications in localDB
  _service.gotBackgroundNotification(message, syncServer: false);
}

Notification payload

{
  data: {
    data: '{"notificationType":"MESSAGE:INSERT","channelId":"63243103a4c87100078d8996","channelTitle":"Bears","userId":"632430fbe99b9900078c4701","userName":"Alice Owlman","messageId":"632428095723cb1d55efe8f5","message":"we need to have it","attachments":[],"date":"2022-09-16 08:17:09.096Z","workspaceId":"632427b7e99b9900078c44f5","isComplete":true}',
  },
  notification: {
    title: 'Alice Owlman',
    body: 'we need to have it',
    imageUrl: undefined,
  },
  tokens: ['XXXXXX', 'YYYYYYY'],
  android: {
    priority: 'high',
  },
  apns: {
    payload: {
      aps: {
        contentAvailable: true,
      },
    },
  },
}

Flutter doctor

Click To Expand ``` flutter doctor Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel stable, 3.0.5, on Microsoft Windows [Version 10.0.22622.598], locale en-US) [√] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc2) [√] Chrome - develop for the web [!] Visual Studio - develop for Windows (Visual Studio Community 2022 17.1.3) ! Unable to locate a Windows 10 SDK. If building fails, install the Windows 10 SDK in Visual Studio. [√] Android Studio (version 2021.1) [√] VS Code (version 1.70.0) [√] Connected device (3 available) [√] HTTP Host Availability ! Doctor found issues in 1 category. ```

Flutter dependencies

Click To Expand ``` flutter pub deps -- --style=compact Dart SDK 2.17.6 Flutter SDK 3.0.5 chatworld_app 1.0.0+1 dependencies: - bloc_test 9.0.3 [bloc diff_match_patch meta mocktail test] - cached_network_image 3.2.1 [flutter flutter_cache_manager octo_image cached_network_image_platform_interface cached_network_image_web] - connectivity_plus 2.3.6+1 [flutter connectivity_plus_platform_interface connectivity_plus_linux connectivity_plus_macos connectivity_plus_web connectivity_plus_windows] - cupertino_icons 1.0.4 - dartz 0.10.1 - device_info_plus 4.0.0 [flutter device_info_plus_platform_interface device_info_plus_macos device_info_plus_linux device_info_plus_web device_info_plus_windows] - emoji_picker_flutter 1.3.0 [flutter shared_preferences] - equatable 2.0.3 [collection meta] - event_bus 2.0.0 - extended_image 6.2.1 [extended_image_library flutter meta] - firebase_analytics 9.3.3 [firebase_analytics_platform_interface firebase_analytics_web firebase_core firebase_core_platform_interface flutter] - firebase_core 1.21.1 [firebase_core_platform_interface firebase_core_web flutter meta] - firebase_crashlytics 2.8.9 [firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface flutter stack_trace] - firebase_messaging 11.4.4 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta] - flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine] - flutter_bloc 8.0.1 [flutter bloc provider] - flutter_keyboard_visibility 5.3.0 [meta flutter_keyboard_visibility_platform_interface flutter_keyboard_visibility_web flutter] - flutter_local_notifications 9.9.1 [clock flutter flutter_local_notifications_linux flutter_local_notifications_platform_interface timezone] - flutter_localizations 0.0.0 [flutter intl characters clock collection material_color_utilities meta path vector_math] - flutter_markdown 0.6.10+5 [flutter markdown meta path] - flutter_portal 1.1.1 [collection flutter vector_math] - flutter_secure_storage 5.0.2 [meta flutter flutter_secure_storage_linux flutter_secure_storage_macos flutter_secure_storage_platform_interface flutter_secure_storage_web flutter_secure_storage_windows] - flutter_spinkit 5.1.0 [flutter] - flutter_staggered_grid_view 0.6.2 [flutter] - flutter_svg 1.0.3 [flutter meta path_drawing vector_math xml] - get_it 7.2.0 [async collection] - http 0.13.4 [async http_parser meta path] - internet_connection_checker 0.0.1+4 - intl 0.17.0 [clock path] - markdown 5.0.0 [args charcode meta] - objectbox 1.6.2 [collection flat_buffers ffi meta path] - objectbox_flutter_libs 1.6.2 [objectbox path_provider] - path_provider 2.0.9 [flutter path_provider_android path_provider_ios path_provider_linux path_provider_macos path_provider_platform_interface path_provider_windows] - photo_view 0.14.0 [flutter] - queue 3.1.0+1 - quiver 3.1.0 [matcher] - rxdart 0.27.5 - shared_preferences 2.0.13 [flutter shared_preferences_android shared_preferences_ios shared_preferences_linux shared_preferences_macos shared_preferences_platform_interface shared_preferences_web shared_preferences_windows] - sticky_grouped_list 3.1.0 [flutter scrollable_positioned_list meta] - url_launcher 6.1.5 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows] dev dependencies: - build_runner 2.1.7 [args async analyzer build build_config build_daemon build_resolvers build_runner_core code_builder collection crypto dart_style frontend_server_client glob graphs http_multi_server io js logging meta mime package_config path pool pub_semver pubspec_parse shelf shelf_web_socket stack_trace stream_transform timing watcher web_socket_channel yaml] - flutter_lints 1.0.4 [lints] - flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charcode collection matcher material_color_utilities meta source_span stream_channel string_scanner term_glyph] - mocktail 0.3.0 [collection matcher test] - objectbox_generator 1.6.2 [objectbox analyzer build collection dart_style glob path source_gen pubspec_parse yaml] transitive dependencies: - _fe_analyzer_shared 31.0.0 [meta] - analyzer 2.8.0 [_fe_analyzer_shared cli_util collection convert crypto glob meta package_config path pub_semver source_span watcher yaml] - args 2.3.0 - async 2.8.2 [collection meta] - bloc 8.0.3 [meta] - boolean_selector 2.1.0 [source_span string_scanner] - build 2.2.1 [analyzer async convert crypto glob logging meta path] - build_config 1.0.0 [checked_yaml json_annotation path pubspec_parse yaml] - build_daemon 3.0.1 [built_collection built_value http_multi_server logging path pool shelf shelf_web_socket stream_transform watcher web_socket_channel] - build_resolvers 2.0.6 [analyzer async build crypto graphs logging path package_config pool pub_semver stream_transform yaml] - build_runner_core 7.2.3 [async build build_config build_resolvers collection convert crypto glob graphs json_annotation logging meta path package_config pool timing watcher yaml] - built_collection 5.1.1 - built_value 8.1.4 [built_collection collection fixnum meta] - cached_network_image_platform_interface 1.0.0 [flutter flutter_cache_manager] - cached_network_image_web 1.0.1 [flutter flutter_cache_manager cached_network_image_platform_interface] - characters 1.2.0 - charcode 1.3.1 - checked_yaml 2.0.1 [json_annotation source_span yaml] - cli_util 0.3.5 [meta path] - clock 1.1.0 - code_builder 4.1.0 [built_collection built_value collection matcher meta] - collection 1.16.0 - connectivity_plus_linux 1.3.1 [flutter connectivity_plus_platform_interface meta nm] - connectivity_plus_macos 1.2.4 [connectivity_plus_platform_interface flutter] - connectivity_plus_platform_interface 1.2.1 [flutter meta plugin_platform_interface] - connectivity_plus_web 1.2.3 [connectivity_plus_platform_interface flutter_web_plugins flutter] - connectivity_plus_windows 1.2.2 [connectivity_plus_platform_interface flutter] - convert 3.0.1 [typed_data] - coverage 1.0.3 [args logging package_config path source_maps stack_trace vm_service] - crypto 3.0.1 [collection typed_data] - dart_style 2.2.1 [analyzer args path pub_semver source_span] - dbus 0.7.1 [args ffi meta xml] - device_info_plus_linux 2.1.1 [device_info_plus_platform_interface file flutter meta] - device_info_plus_macos 2.2.3 [device_info_plus_platform_interface flutter] - device_info_plus_platform_interface 2.3.0+1 [flutter meta plugin_platform_interface] - device_info_plus_web 2.1.0 [device_info_plus_platform_interface flutter_web_plugins flutter] - device_info_plus_windows 2.1.1 [device_info_plus_platform_interface ffi flutter win32] - diff_match_patch 0.4.1 - extended_image_library 3.3.0 [crypto flutter http_client_helper path path_provider] - fake_async 1.3.0 [clock collection] - ffi 1.1.2 - file 6.1.2 [meta path] - firebase_analytics_platform_interface 3.3.3 [firebase_core flutter meta plugin_platform_interface] - firebase_analytics_web 0.4.2+3 [firebase_analytics_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js] - firebase_core_platform_interface 4.5.1 [collection flutter flutter_test meta plugin_platform_interface] - firebase_core_web 1.7.2 [firebase_core_platform_interface flutter flutter_web_plugins js meta] - firebase_crashlytics_platform_interface 3.2.15 [collection firebase_core flutter meta plugin_platform_interface] - firebase_messaging_platform_interface 3.5.4 [firebase_core flutter meta plugin_platform_interface] - firebase_messaging_web 2.4.4 [firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta] - fixnum 1.0.0 - flat_buffers 2.0.5 - flutter_blurhash 0.6.4 [flutter] - flutter_cache_manager 3.3.0 [clock collection file flutter http path path_provider pedantic rxdart sqflite uuid] - flutter_keyboard_visibility_platform_interface 2.0.0 [flutter meta plugin_platform_interface] - flutter_keyboard_visibility_web 2.0.0 [flutter_keyboard_visibility_platform_interface flutter_web_plugins flutter] - flutter_local_notifications_linux 0.5.1 [flutter flutter_local_notifications_platform_interface dbus path xdg_directories] - flutter_local_notifications_platform_interface 5.0.0 [flutter plugin_platform_interface] - flutter_secure_storage_linux 1.1.0 [flutter flutter_secure_storage_platform_interface] - flutter_secure_storage_macos 1.1.0 [flutter flutter_secure_storage_platform_interface] - flutter_secure_storage_platform_interface 1.0.0 [flutter plugin_platform_interface] - flutter_secure_storage_web 1.0.2 [flutter flutter_web_plugins flutter_secure_storage_platform_interface js] - flutter_secure_storage_windows 1.1.2 [flutter flutter_secure_storage_platform_interface] - flutter_web_plugins 0.0.0 [flutter js characters collection material_color_utilities meta vector_math] - frontend_server_client 2.1.2 [async path] - glob 2.0.2 [async collection file path string_scanner] - graphs 2.1.0 [collection] - http_client_helper 2.0.3 [http] - http_multi_server 3.2.0 [async] - http_parser 4.0.0 [charcode collection source_span string_scanner typed_data] - io 1.0.3 [meta path string_scanner] - js 0.6.4 - json_annotation 4.4.0 [meta] - lints 1.0.1 - logging 1.0.2 - matcher 0.12.11 [stack_trace] - material_color_utilities 0.1.4 - meta 1.7.0 - mime 1.0.1 - nested 1.0.0 [flutter] - nm 0.5.0 [dbus] - node_preamble 2.0.1 - octo_image 1.0.1 [flutter flutter_blurhash] - package_config 2.0.2 [path] - path 1.8.1 - path_drawing 1.0.0 [vector_math meta path_parsing flutter] - path_parsing 1.0.0 [vector_math meta] - path_provider_android 2.0.12 [flutter path_provider_platform_interface] - path_provider_ios 2.0.8 [flutter path_provider_platform_interface] - path_provider_linux 2.1.5 [ffi flutter path path_provider_platform_interface xdg_directories] - path_provider_macos 2.0.5 [flutter path_provider_platform_interface] - path_provider_platform_interface 2.0.3 [flutter platform plugin_platform_interface] - path_provider_windows 2.0.5 [ffi flutter path path_provider_platform_interface win32] - pedantic 1.11.1 - petitparser 4.4.0 [meta] - platform 3.1.0 - plugin_platform_interface 2.1.2 [meta] - pool 1.5.0 [async stack_trace] - process 4.2.4 [file path platform] - provider 6.0.2 [collection flutter nested] - pub_semver 2.1.0 [collection meta] - pubspec_parse 1.2.0 [checked_yaml collection json_annotation pub_semver yaml] - scrollable_positioned_list 0.3.4 [flutter collection] - shared_preferences_android 2.0.11 [flutter shared_preferences_platform_interface] - shared_preferences_ios 2.1.0 [flutter shared_preferences_platform_interface] - shared_preferences_linux 2.1.0 [file flutter path path_provider_linux path_provider_platform_interface shared_preferences_platform_interface] - shared_preferences_macos 2.0.3 [flutter shared_preferences_platform_interface] - shared_preferences_platform_interface 2.0.0 [flutter] - shared_preferences_web 2.0.3 [flutter flutter_web_plugins shared_preferences_platform_interface] - shared_preferences_windows 2.1.0 [file flutter path path_provider_platform_interface path_provider_windows shared_preferences_platform_interface] - term_glyph 1.2.0 - test 1.20.2 [analyzer async boolean_selector collection coverage http_multi_server io js node_preamble package_config path pool shelf shelf_packages_handler shelf_static shelf_web_socket source_span stack_trace stream_channel typed_data web_socket_channel webkit_inspection_protocol yaml test_api test_core] - test_api 0.4.9 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher] - test_core 0.4.11 [analyzer async args boolean_selector collection coverage frontend_server_client glob io meta package_config path pool source_map_stack_trace source_maps source_span stack_trace stream_channel vm_service yaml matcher test_api] - timezone 0.8.0 [path] - timing 1.0.0 [json_annotation] - typed_data 1.3.0 [collection] - url_launcher_android 6.0.15 [flutter url_launcher_platform_interface] - url_launcher_ios 6.0.15 [flutter url_launcher_platform_interface] - url_launcher_linux 2.0.3 [flutter] - url_launcher_macos 2.0.3 [flutter] - url_launcher_platform_interface 2.1.0 [flutter plugin_platform_interface] - url_launcher_web 2.0.9 [flutter flutter_web_plugins url_launcher_platform_interface] - url_launcher_windows 2.0.2 [flutter] - uuid 3.0.6 [crypto] - vector_math 2.1.2 - vm_service 7.5.0- watcher 1.0.1 [async path] - web_socket_channel 2.1.0 [async crypto stream_channel] - webkit_inspection_protocol 1.0.0 [logging] - win32 2.4.1 [ffi] - xdg_directories 0.2.0+1 [meta path process] - xml 5.3.1 [collection meta petitparser] - yaml 3.1.0 [collection source_span string_scanner] ```

iosephmagno commented 1 year ago

You forgot to write your notification payload, but there are two potential issues:

1) you are using data-only notifications. It is already known that onBackgroundMessage is not invoked on iOS after some time if app is terminated and user switched to a different app. The solution is to use remote notifications, but due to current lack of support for mutable-content:1 and service app extention, we cannot use them if we need to modify content before displaying head ups, https://github.com/firebase/flutterfire/issues/9381#issuecomment-1229167020

2) you are using remote notifications. These ones are solid, but as mentioned above we cannot use them on iOS if we need to modify content, and it has been noticed that onBackgroundMessage might again not be invoked when app is killed if user switches to different app and certain random system conditions at met (eg. Incoming notification volume/frequency, time, etc). https://github.com/firebase/flutterfire/issues/9536#issuecomment-1248284780

baraaaljabban commented 1 year ago

@iosephmagno I updated the description and added the payload, but I'm not sure if it's the same that mentioned up or not, however, I don't think the first one is the same but I'll do more testing and update this thread.

darshankawar commented 1 year ago

Thanks for the report @baraaaljabban Can you try using the latest plugin version ? https://pub.dev/packages/firebase_messaging/changelog#1302 It has a fix to use @pragma('vm:entry-point') annotation for messaging background handler

Also, please try using the plugin example and see if using it, you still get same behavior or not.

iosephmagno commented 1 year ago

@darshankawar we also upgraded to 13.0.2, added @pragma annotation and have same code of official example. Still data-only notification stops to work when app is terminated and user switches to another app.

Video here, when we open that flutter Demo Page app, onBackgroundMessage is no longer invoked.

https://user-images.githubusercontent.com/83366073/190626795-61a20272-6507-4ba7-938d-8123422de30a.MOV

Since this is the expected behavior (source: Apple) and you guys keep saying that things work on your side, can you please share your videos which demonstrates your assertion? Video should display that head ups are shown successfully.

Beyound that, Apple confirms that data-only notifications are not meant to be used to deliver notifications for “chat messages” or similar “high priority” messages. They might arrive with huge delay or not arrive at all under several condition.

Official solution told by Apple is to use remote notification with mutable-content:1 and service app extention. Would you be so kind as to tell us whether this feature is under development or not? Without it, we cannot use firebase messaging.

iosephmagno commented 1 year ago

@baraaaljabban can you try adding apns-push-type to your payload?

"aps" : { 
"content_available" : true 
},
 "apns-push-type": "background",
 "apns-priority": "5",
 "apns-topic": "your_app_bundle_id"
 }

baraaaljabban commented 1 year ago

@darsha I updated the plugin, added the Param thing and used the same example giving in that link , but still I'm getting the same behavior over and over again unfortunately 😔

baraaaljabban commented 1 year ago

@iosephmagno will try to do it & will let you know if it made a difference

techttiru commented 1 year ago

@iosephmagno Hi, i am also facing the same problem and i tried your suggestion. actually it works but not consistently. sometimes works and sometime is not working. so whenever its not working, if i go ahead and change the priority number anything between 5 to 10 then it started to working. then later again its not working.

also, lets assume my app is running background and if i opened up whatapp then if i try sending message, i never received message. then i have to change the priority and if i try then for some time its working if we close whats app. lot of unexpected behavior is happening. unable to predict whats going on there. its not consistent.

   const message = {
        data: {messageData: finalMessagePayload},
   contentAvailable: true,
         priority: "high",
         "aps" : {
          "content_available" : true
          },
          "apns-push-type": "background",
          "apns-priority": "8",
          "apns-topic": "my app bundle id",
        tokens: [androidToken, iosToken],
      };

mine, i use firebase cloud function with typescript running in node.js.

iosephmagno commented 1 year ago

@techttiru good to know you make it! “priority” field can be set only to 5 or 10, but Apple forces data-only notifications’ priority to 5. Delivery inconsistency is due to Apple’s restrictions for data-only notifications, not your fault.

As for your last point, this is a known issue and firebase_messaging team is on it #9536

When their fix lands, data-only notifications on iOS will work as expected 👍 However, due to Apple restrictions (iOS throttles the amount of times they can be used), they are not to use when “high-priority” and “delivery consistency” is required.

darshankawar commented 1 year ago

@darsha I updated the plugin, added the Param thing and used the same example giving in that link , but still I'm getting the same behavior over and over again unfortunately 😔

@baraaaljabban Is _firebaseMessagingBackgroundHandler in your app declared as the top-level function like in plugin example ?

Also, from the sample code you shared in your original description, it seems to be using Isolate. Does the same behavior replicate without using it ? Not sure if https://github.com/firebase/flutterfire/issues/8175 would be related or not.

baraaaljabban commented 1 year ago

Hi @darshankawar yes it is a top level function, and removed the isolate completely (and I don't think that was the issue as I'm calling the current one) to check if it will make any difference and run in on the main function as the snippet up, but the same issue still occur but more often.

darshankawar commented 1 year ago

@baraaaljabban I tried the plugin example on iOS device using latest master version of the framework. I ran it in --release mode, because in debug mode if we terminate app on iOS, we can't open it again as you might know. So, in release mode, app compiled, I updated the generated fcm token in send-message.js file, gave required permission for the app and then terminated it by swiping it away. Then using npm run send-message command, sent 15 notifications back to back which were triggered and received on my phone properly. Then from notification tray, tapping on each of them opened the app properly as shown in below videos.

Note that, due to upload size limit, I divided video into two parts which shows the steps I mentioned above.

https://user-images.githubusercontent.com/67046386/191005131-c0242403-be27-461f-a79f-b6905783d760.MOV

https://user-images.githubusercontent.com/67046386/191005109-ce7bb30a-3f1b-4da0-8ae7-aa65c7c4031b.MOV

Do you not see the same behavior after running the plugin example ? Or you get a different behavior ? ie, the app doesn't open after tapping on notifications from the tray ?

baraaaljabban commented 1 year ago

thanks @darshankawar, but my issue was about the code that you put inside onBackgroundMessage ( for example you can create app and try to save every single notification comes in, or report to Firebase, or anything that will give a visibility to you on how many notifications where handled. like maybe you can save a list in the local database and call it later to check if you were able to save all notifications or you will miss some ) then you will see that sometimes the code onBackgroundMessage will be executed or called and sometimes it's not. I don't have issue to open the app from a notification or so, and I'm receiving all the notification and I can see it in the tray. as fare as I know onBackgroundMessage is not responsible for opining the app from the tray ,but instead execute a code inside it once notification comes in ,( handler for a message once comes in if the app is killed or in the background).
I hope I made myself clear here.

darshankawar commented 1 year ago

Thanks for the update. I have shared this scenario with the team so they can have a look when they have time. Keeping this issue open and labeling.

russellwheatley commented 1 year ago

Hello everyone, we’ve reviewed the issues opened for iOS background messages and we want to make our position clear.

Android and iOS handle background messaging differently. The decision made by the iOS operating system whether messages reaches the relevant iOS event handler (and subsequently received by the Dart background messaging handler) is based on a number of criteria, such as: CPU usage, priority level (data-only messages are considered “low priority” by iOS, android does not), battery level, amount of messages being received by the app, background/terminated application state, etc. This is a fundamental difference between the platforms, and you need to be aware of them when designing your application.

One solution suggested for iOS data-only messages unreliability has been to add a NotificationExtension. But this will still not create parity with Android as you will still have to include a notification with your message (therefore not data-only). It will still render the original notification if you do not update/mutate the notification that comes through the system in a timely manner. We are not currently considering this as a solution due to these limitations.

We also will not support non-FCM messages from third party packages. We specifically only support messages received from the Firebase APIs since we cannot guarantee that messages received from third party packages will not have any unintended side-effects on other Firebase products such as messaging delivery reporting and Analytics data.

To help us triage and locate genuine issues that need to be addressed we have created a specific issue template for iOS background messages. If you believe you still have an issue that needs to be addressed, please create a new issue following this template.

I will be closing this issue in favor of raising a new issue with the new template above. This template will help you provide us with all the information we need to investigate a potential issue with background messaging on iOS.

iosephmagno commented 1 year ago

Hello @russellwheatley. I think the point shoudn’t be discussing on the unfeasibility of creating parity with silent notification on android (that’s a fact), but to fully support iOS. Without Notification Extension, it is impossible to display notifications on iOS if content is ecrypted.

We’ve investigated the issue a lot, but unfortunately it seems there is no way to workaround this feature.

baraaaljabban commented 1 year ago

Hi @darshankawar & @russellwheatley , I read the comment above and I don't think my issue is related to the IOS background issue. as I'm receiving the notifications on both devices with no issue and we are using FireBase to deliver the notifications, but as I said the code inside the onBackgroundMessage() is not executing every time, especially the first couple of notifications that is coming in.

and the following template. is only for IOS issue and mine is a bit different and happening for both [Android & IOS]

would you please advice what to do, because I'm still facing the issue.