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.6k stars 3.95k forks source link

🐛 [firebase_messaging] data message is not delivered in iOS. #8197

Closed codesniper9315 closed 2 years ago

codesniper9315 commented 2 years ago

Bug report

Describe the bug Currently I am developing the social networking app for Android and iOS with flutter. We send the notification in many cases. Btw the problem is that if we send the notification with only data payload, it is not delivered to the iOS device (for android working perfect). I tested also through firebase console by sending both of notification & data payload to make sure the configuration succeed or not. In this case the notification was delivered after 3 minutes (without schedule). We send the notification from our cloud functions.

Sample project

The code which send notification from cloud function below.

const notificationPayload = {
    data: {
        title: "title here",
        body: "body here",
        click_action: "FLUTTER_NOTIFICATION_CLICK",
    },
};

const notificationPayloadEL = {
    data: {
        title: "title here",
        body: "body here",
        click_action: "FLUTTER_NOTIFICATION_CLICK",
    },
};
const options = {
    priority: "high",
};
if (userPayload.lang === undefined || userPayload.lang === "en") {
    await firebaseMessaging.sendToDevice([userPayload.deviceToken], notificationPayload, options);
} else {
    await firebaseMessaging.sendToDevice([userPayload.deviceToken], notificationPayloadEL, options);
}

Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand ``` [√] Flutter (Channel stable, 2.10.1, on Microsoft Windows [Version 10.0.19042.1526], locale en-US) [√] Android toolchain - develop for Android devices (Android SDK version 31.0.0) [√] Chrome - develop for the web [!] Visual Studio - develop for Windows (Visual Studio Build Tools 2019 16.11.9) X Visual Studio is missing necessary components. Please re-run the Visual Studio installer for the "Desktop development with C++" workload, and include these components: MSVC v142 - VS 2019 C++ x64/x86 build tools - If there are multiple build tool versions available, install the latest C++ CMake tools for Windows Windows 10 SDK [√] Android Studio (version 4.2) [√] VS Code (version 1.64.2) [√] Connected device (4 available) [√] HTTP Host Availability ```

Flutter dependencies

Run flutter pub deps -- --style=compact and paste the output below:

Click To Expand ``` Dart SDK 2.16.1 Flutter SDK 2.10.1 sportflik_app 1.0.0+1 dependencies: - agora_rtc_engine 4.2.1 [flutter flutter_web_plugins json_annotation] - algolia 1.0.4 [meta http uuid] - audio_session 0.1.6+1 [flutter flutter_web_plugins rxdart meta] - badges 2.0.2 [flutter] - cached_network_image 3.2.0 [flutter flutter_cache_manager octo_image cached_network_image_platform_interface cached_network_image_web] - camera 0.9.4+14 [camera_platform_interface camera_web flutter flutter_plugin_android_lifecycle quiver] - cloud_firestore 3.1.10 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta] - cupertino_icons 1.0.4 - easy_localization 3.0.0 [flutter shared_preferences intl args path easy_logger flutter_localizations] - enum_to_string 2.0.1 - file_support 1.0.3+6 [flutter dio logger http_parser path_provider http uuid mime_type flutter_image_compress path permission_handler] - firebase_analytics 9.1.2 [firebase_analytics_platform_interface firebase_analytics_web firebase_core firebase_core_platform_interface flutter] - firebase_auth 3.3.9 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta] - firebase_core 1.13.1 [firebase_core_platform_interface firebase_core_web flutter meta] - firebase_database 9.0.8 [firebase_core firebase_core_platform_interface firebase_database_platform_interface firebase_database_web flutter] - firebase_dynamic_links 4.0.8 [firebase_core firebase_core_platform_interface firebase_dynamic_links_platform_interface flutter meta plugin_platform_interface] - firebase_messaging 11.2.8 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta] - firebase_storage 10.2.9 [firebase_core firebase_core_platform_interface firebase_storage_platform_interface firebase_storage_web flutter] - flutter 0.0.0 [characters collection material_color_utilities meta typed_data vector_math sky_engine] - flutter_cache_manager 3.3.0 [clock collection file flutter http path path_provider pedantic rxdart sqflite uuid] - flutter_colorpicker 1.0.3 [flutter] - flutter_facebook_auth 3.5.7 [flutter flutter_facebook_auth_platform_interface flutter_facebook_auth_web] - flutter_link_previewer 2.6.3 [flutter flutter_chat_types flutter_linkify html http linkify meta url_launcher] - flutter_local_notifications 9.3.2 [clock flutter flutter_local_notifications_linux flutter_local_notifications_platform_interface timezone] - flutter_screenutil 5.3.1 [flutter] - flutter_sound 8.5.0 [path_provider recase uuid provider path synchronized logger flutter flutter_sound_platform_interface flutter_sound_web] - flutter_spinkit 5.1.0 [flutter] - flutter_svg 1.0.3 [flutter meta path_drawing vector_math xml] - flutter_swiper_null_safety 1.0.2 [flutter] - focus_detector 2.0.1 [flutter visibility_detector] - geolocator 8.2.0 [flutter geolocator_platform_interface geolocator_android geolocator_apple geolocator_web geolocator_windows] - google_fonts 2.3.1 [flutter http path_provider crypto] - google_maps_flutter 2.1.1 [flutter flutter_plugin_android_lifecycle google_maps_flutter_platform_interface] - google_sign_in 5.2.4 [flutter google_sign_in_platform_interface google_sign_in_web] - image_cropper 1.5.0 [flutter] - image_picker 0.8.4+10 [flutter flutter_plugin_android_lifecycle image_picker_for_web image_picker_platform_interface] - just_audio 0.9.20 [just_audio_platform_interface just_audio_web audio_session rxdart path path_provider async uuid crypto meta flutter] - media_info 0.9.0 [mime flutter] - permission_handler 8.3.0 [flutter meta permission_handler_platform_interface] - photofilters 3.0.1 [flutter image meta path_provider] - provider 6.0.2 [collection flutter nested] - share 2.0.4 [meta mime flutter] - 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] - shimmer 2.0.0 [flutter] - sign_in_with_apple 3.3.0 [flutter meta sign_in_with_apple_platform_interface sign_in_with_apple_web] - sliding_sheet 0.5.2 [flutter] - smooth_page_indicator 1.0.0+2 [flutter] - story_view 0.13.2 [flutter flutter_cache_manager rxdart video_player collection] - string_validator 0.3.0 - tapioca 1.0.5+2 [flutter] - timeago 3.2.2 - url_launcher 6.0.20 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows] - video_player 2.2.19 [flutter html video_player_android video_player_avfoundation video_player_platform_interface video_player_web] - video_thumbnail 0.4.3 [flutter] - video_trimmer 1.0.0 [flutter video_player ffmpeg_kit_flutter_min_gpl video_thumbnail path_provider intl path] dev dependencies: - flutter_launcher_icons 0.9.2 [args image path 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 typed_data] transitive dependencies: - archive 3.2.1 [crypto path] - args 2.3.0 - async 2.8.2 [collection meta] - boolean_selector 2.1.0 [source_span string_scanner] - 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] - camera_platform_interface 2.1.5 [cross_file flutter plugin_platform_interface stream_transform] - camera_web 0.2.1+3 [camera_platform_interface flutter flutter_web_plugins stream_transform] - characters 1.2.0 - charcode 1.3.1 - clock 1.1.0 - cloud_firestore_platform_interface 5.5.1 [collection firebase_core flutter meta plugin_platform_interface] - cloud_firestore_web 2.6.10 [cloud_firestore_platform_interface collection firebase_core firebase_core_web flutter flutter_web_plugins js] - collection 1.15.0 - cross_file 0.3.2 [flutter js meta] - crypto 3.0.1 [collection typed_data] - csslib 0.17.1 [source_span] - dbus 0.7.1 [args ffi meta xml] - dio 4.0.4 [http_parser path] - easy_logger 0.0.2 [flutter] - equatable 2.0.3 [collection meta] - fake_async 1.2.0 [clock collection] - ffi 1.1.2 - ffmpeg_kit_flutter_min_gpl 4.5.1 [ffmpeg_kit_flutter_platform_interface flutter] - ffmpeg_kit_flutter_platform_interface 0.2.1 [flutter plugin_platform_interface] - file 6.1.2 [meta path] - firebase_analytics_platform_interface 3.1.1 [firebase_core flutter meta plugin_platform_interface] - firebase_analytics_web 0.4.0+8 [firebase_analytics_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js] - firebase_auth_platform_interface 6.2.1 [firebase_core flutter meta plugin_platform_interface] - firebase_auth_web 3.3.9 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser intl js meta] - firebase_core_platform_interface 4.2.5 [collection flutter meta plugin_platform_interface] - firebase_core_web 1.6.1 [firebase_core_platform_interface flutter flutter_web_plugins js meta] - firebase_database_platform_interface 0.2.1+1 [collection firebase_core flutter meta plugin_platform_interface] - firebase_database_web 0.2.0+7 [firebase_core firebase_core_web firebase_database_platform_interface flutter flutter_web_plugins js] - firebase_dynamic_links_platform_interface 0.2.1+1 [firebase_core flutter meta plugin_platform_interface] - firebase_messaging_platform_interface 3.2.1 [firebase_core flutter meta plugin_platform_interface] - firebase_messaging_web 2.2.9 [firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta] - firebase_storage_platform_interface 4.1.1 [collection firebase_core flutter meta plugin_platform_interface] - firebase_storage_web 3.2.10 [async firebase_core firebase_core_web firebase_storage_platform_interface flutter flutter_web_plugins http js meta] - flutter_blurhash 0.6.4 [flutter] - flutter_chat_types 3.3.1 [equatable json_annotation meta] - flutter_facebook_auth_platform_interface 2.7.1 [flutter plugin_platform_interface] - flutter_facebook_auth_web 2.6.0+2 [flutter flutter_web_plugins js flutter_facebook_auth_platform_interface] - flutter_image_compress 1.1.0 [flutter] - flutter_linkify 5.0.2 [flutter linkify] - flutter_local_notifications_linux 0.4.2 [flutter flutter_local_notifications_platform_interface dbus path xdg_directories] - flutter_local_notifications_platform_interface 5.0.0 [flutter plugin_platform_interface] - flutter_localizations 0.0.0 [flutter intl characters clock collection material_color_utilities meta path typed_data vector_math] - flutter_plugin_android_lifecycle 2.0.5 [flutter] - flutter_sound_platform_interface 8.5.0 [flutter meta plugin_platform_interface logger] - flutter_sound_web 8.5.0 [flutter_sound_platform_interface flutter logger flutter_web_plugins meta js] - flutter_web_plugins 0.0.0 [flutter js characters collection material_color_utilities meta typed_data vector_math] - geolocator_android 3.1.0 [flutter geolocator_platform_interface] - geolocator_apple 2.1.1+1 [flutter geolocator_platform_interface] - geolocator_platform_interface 4.0.3 [flutter plugin_platform_interface vector_math meta] - geolocator_web 2.1.4 [flutter flutter_web_plugins geolocator_platform_interface] - geolocator_windows 0.1.0 [flutter geolocator_platform_interface] - google_maps_flutter_platform_interface 2.1.5 [collection flutter plugin_platform_interface stream_transform] - google_sign_in_platform_interface 2.1.2 [flutter quiver] - google_sign_in_web 0.10.0+5 [flutter flutter_web_plugins google_sign_in_platform_interface js] - html 0.15.0 [csslib source_span] - http 0.13.4 [async http_parser meta path] - http_parser 4.0.0 [charcode collection source_span string_scanner typed_data] - image 3.1.3 [archive meta xml] - image_picker_for_web 2.1.6 [flutter flutter_web_plugins image_picker_platform_interface] - image_picker_platform_interface 2.4.4 [cross_file flutter http plugin_platform_interface] - intl 0.17.0 [clock path] - js 0.6.3 - json_annotation 4.4.0 [meta] - just_audio_platform_interface 4.1.0 [flutter plugin_platform_interface] - just_audio_web 0.4.4 [just_audio_platform_interface flutter flutter_web_plugins] - linkify 4.1.0 - lints 1.0.1 - logger 1.1.0 - matcher 0.12.11 [stack_trace] - material_color_utilities 0.1.3 - meta 1.7.0 - mime 1.0.1 - mime_type 1.0.0 - nested 1.0.0 [flutter] - octo_image 1.0.1 [flutter flutter_blurhash] - path 1.8.0 - path_drawing 1.0.0 [vector_math meta path_parsing flutter] - path_parsing 1.0.0 [vector_math meta] - 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] - 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 - permission_handler_platform_interface 3.7.0 [flutter meta plugin_platform_interface] - petitparser 4.4.0 [meta] - platform 3.1.0 - plugin_platform_interface 2.1.2 [meta] - process 4.2.4 [file path platform] - quiver 3.0.1+1 [matcher] - recase 4.0.0 - rxdart 0.27.3 - 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] - sign_in_with_apple_platform_interface 1.0.0 [flutter plugin_platform_interface meta] - sign_in_with_apple_web 1.0.1 [flutter flutter_web_plugins sign_in_with_apple_platform_interface js] - sky_engine 0.0.99 - source_span 1.8.1 [collection path term_glyph] - sqflite 2.0.2 [flutter sqflite_common path] - sqflite_common 2.2.0 [synchronized path meta] - stack_trace 1.10.0 [path] - stream_channel 2.1.0 [async] - stream_transform 2.0.0 - string_scanner 1.1.0 [charcode source_span] - synchronized 3.0.0 - term_glyph 1.2.0 - test_api 0.4.8 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher] - timezone 0.8.0 [path] - 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 3.0.0 [flutter url_launcher_platform_interface] - url_launcher_macos 3.0.0 [flutter url_launcher_platform_interface] - url_launcher_platform_interface 2.0.5 [flutter plugin_platform_interface] - url_launcher_web 2.0.9 [flutter flutter_web_plugins url_launcher_platform_interface] - url_launcher_windows 3.0.0 [flutter url_launcher_platform_interface] - uuid 3.0.6 [crypto] - vector_math 2.1.1 - video_player_android 2.3.0 [flutter video_player_platform_interface] - video_player_avfoundation 2.3.0 [flutter video_player_platform_interface] - video_player_platform_interface 5.1.0 [flutter plugin_platform_interface] - video_player_web 2.0.7 [flutter flutter_web_plugins video_player_platform_interface] - visibility_detector 0.2.2 [flutter] - 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] ```

Hope someone helps asap to solve this issue. Thanks

darshankawar commented 2 years ago

@flutterdev9715 What's the iOS version you are using ? Does this happen in debug or in release mode ?

We send the notification from our cloud functions.

Can you also try to send it through push notifications or directly through firebase console and see if you still get same behavior ?

codesniper9315 commented 2 years ago

@darshankawar It is happening on various iOS versions. Anyways, I've tested on iOS 14.6.

I tried to send notification through firebase console. I've sent both of notification and data inside the payload in this case it was working but I received the notification after 3 minutes. So I think something is wrong with firebase_messaging plugin.

Hope it is helpful you to figure out the issue.

darshankawar commented 2 years ago

@flutterdev9715 On iOS to receive data message, you'll need to use content-available flag. See below documentation snapshot for your reference: Data-only messages are sent as low priority on both Android and iOS and will not trigger the background handler by default. To enable this functionality, you must set the "priority" to high on Android and enable the content-available flag for iOS in the message payload.

codesniper9315 commented 2 years ago

@darshankawar Thanks for your help. I will try with your suggestion once and update you. Btw on iOS data-only message is not triggered on foreground too.

codesniper9315 commented 2 years ago

I much appreciate your help, @darshankawar It is working perfectly on iOS now.