Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 [firebase_messaging] Notifications get delivered to onMessage instead of to the system tray on iOS #3466

Closed
rubenvereecken opened this issue Sep 5, 2020 · 1 comment · Fixed by #4012
Labels
Needs Attention This issue needs maintainer attention. type: bug Something isn't working

Comments

@rubenvereecken
Copy link

Bug report

First off, I've got both display and data messages working beautifully on Android, and just data messages on iOS. The problem is with display messages (notifications) on iOS. The problem also seems straightforward though I've not found any other issues or documentation referencing anything quite like it.

When I send a notification (with notification payload) to my iOS client (written with Flutter), no notification shows up in the system tray while the app is closed. Instead, upon opening the app, the onMessage message handler is called. This is in direction contradiction of the docs, which state unambiguously that onMessage will never be called for notifications while the app is in the background.

I can't think of anything I've done out of the ordinary. No method swizzling. What's going on?

Steps to reproduce

Steps to reproduce the behavior:

  • Code as below
  • Grab Firebase registration token from the debug version running on a real iOS phone
  • Send app to background
  • Send test notification through Firebase console
  • ... nothing happens until I open the app, at which point the wrong message handler is called

firebase_notifications.dart

  void setupFirebaseCloudMessagingListeners() {
    if (Platform.isIOS) IOSPermission();
    _messaging.configure(
      onMessage: (Map<String, dynamic> message) {
        print('on message $message');
        return messageHandler(message);
      },
      // Only available on Android apparently
      onBackgroundMessage: Platform.isIOS ? null : (Map<String, dynamic> message) {
        print('on background $message');
        return messageHandler(message);
      },
      onResume: (Map<String, dynamic> message) async {
        print('on resume $message');
        await navigateAccordingly(message);
      },
      onLaunch: (Map<String, dynamic> message) async {
        print('on launch $message');
        await navigateAccordingly(message);
      },
    );
  }

AppDelegate.swift

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

Expected behavior

Instead of onMessage being called upon opening the app, the notification should have been delivered to the system tray while the app was in the background.


Additional context

The phone is running iOS 13.5.1. All notification settings are enabled for the app. Run through flutter run in the Android Studio.


Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand
[✓] Flutter (Channel stable, 1.20.2, on Mac OS X 10.15.6 19G73, locale en-GB)
    • Flutter version 1.20.2 at /Users/lessgo/lessgo/flutter
    • Framework revision bbfbf1770c (3 weeks ago), 2020-08-13 08:33:09 -0700
    • Engine revision 9d5b21729f
    • Dart version 2.9.1

 
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at /Users/lessgo/Library/Android/sdk
    • Platform android-30, build-tools 30.0.2
    • Java binary at: /Applications/Android
      Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
    ✗ Android licenses not accepted.  To resolve this, run: flutter doctor
      --android-licenses

[✓] Xcode - develop for iOS and macOS (Xcode 11.5)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.5, Build version 11E608c
    • CocoaPods version 1.9.1

[✓] Android Studio (version 4.0)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 48.1.2
    • Dart plugin version 193.7361
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

[✓] VS Code (version 1.48.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.13.2

[✓] Connected device (1 available)
    • Ruben’s iPhone (mobile) • 00008030-00012062022B802E • ios • iOS 13.5.1```

</details>

---

### Flutter dependencies

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

<details><summary>Click To Expand</summary>

Dart SDK 2.9.1
Flutter SDK 1.20.2

dependencies:

  • auto_size_text 2.1.0 [flutter]
  • cached_network_image 2.3.1 [flutter flutter_cache_manager octo_image]
  • cupertino_icons 0.1.3
  • dio 3.0.10 [http_parser path]
  • equatable 1.2.4 [collection meta]
  • firebase_analytics 5.0.16 [meta flutter firebase_analytics_web firebase_analytics_platform_interface]
  • firebase_auth 0.16.1 [meta firebase_core firebase_auth_platform_interface firebase_auth_web flutter]
  • firebase_core 0.4.5 [firebase_core_platform_interface flutter meta firebase_core_web]
  • firebase_messaging 6.0.16 [meta platform flutter]
  • firebase_remote_config 0.3.1+1 [flutter]
  • flare_splash_screen 3.0.1 [flare_loading flutter]
  • flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine]
  • flutter_markdown 0.4.4 [flutter markdown meta path]
  • flutter_portal 0.1.0 [flutter]
  • flutter_speed_dial 1.2.5 [flutter]
  • google_maps_flutter 0.5.30 [flutter flutter_plugin_android_lifecycle google_maps_flutter_platform_interface]
  • horizontal_blocked_scroll_physics 3.0.0 [flutter pedantic]
  • image_cropper 1.3.0 [flutter]
  • image_picker 0.6.7+7 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface]
  • in_app_update 1.1.11 [flutter]
  • intl 0.16.1 [path]
  • jiffy 3.0.1 [intl]
  • location 3.0.2 [flutter meta location_platform_interface location_web]
  • maps_launcher 1.2.2+1 [flutter flutter_web_plugins url_launcher]
  • open_appstore 1.0.2 [flutter]
  • package_info 0.4.3 [flutter]
  • provider 4.3.2+1 [flutter nested collection]
  • pub_semver 1.4.4 [collection]
  • pull_to_refresh 1.6.1 [flutter]
  • quiver 2.1.3 [matcher meta]
  • rxdart 0.24.1
  • shared_preferences 0.5.10 [meta flutter shared_preferences_platform_interface shared_preferences_linux shared_preferences_macos shared_preferences_web]
  • stream_chat_flutter 0.2.6+1 [flutter photo_view rxdart jiffy flutter_portal cached_network_image flutter_markdown url_launcher video_player chewie file_picker image_picker flutter_keyboard_visibility stream_chat mime visibility_detector http_parser]
  • url_launcher 5.5.1 [flutter url_launcher_platform_interface url_launcher_web url_launcher_linux url_launcher_macos]
  • validators 2.0.1 [vin_decoder]
  • visibility_detector 0.1.5 [flutter]
  • workmanager 0.2.3 [flutter]

dev dependencies:

  • cider 0.0.4 [args change intl markdown marker maybe_just_nothing path pub_semver version_manipulation yaml yaml_edit]
  • flutter_driver 0.0.0 [file json_rpc_2 meta path web_socket_channel vm_service_client webdriver flutter flutter_test fuchsia_remote_debug_protocol archive args async boolean_selector characters charcode clock collection convert crypto fake_async intl matcher platform process pub_semver source_span stack_trace stream_channel string_scanner sync_http term_glyph test_api typed_data vector_math]
  • flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charcode collection matcher meta source_span stream_channel string_scanner term_glyph typed_data]
  • mockito 4.1.1 [collection matcher meta test_api]
  • screenshots 2.1.1 [args yaml resource path file archive platform process meta intl tool_mobile]
  • test 1.15.2 [analyzer async boolean_selector coverage http http_multi_server io js node_preamble package_config path pedantic 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]

transitive dependencies:

  • _fe_analyzer_shared 7.0.0 [meta]
  • analyzer 0.39.17 [_fe_analyzer_shared args charcode cli_util collection convert crypto glob html meta package_config path pub_semver source_span watcher yaml]
  • archive 2.0.13 [crypto args path]
  • args 1.6.0
  • asn1lib 0.6.5
  • async 2.4.2 [collection]
  • basic_utils 2.6.2 [http logging json_annotation pointycastle asn1lib convert crypto]
  • boolean_selector 2.0.0 [source_span string_scanner]
  • change 0.1.0 [markdown marker maybe_just_nothing pub_semver]
  • characters 1.0.0
  • charcode 1.1.3
  • chewie 0.9.10 [open_iconic_flutter video_player wakelock flutter]
  • cli_util 0.2.0 [path]
  • clock 1.0.1 [meta]
  • collection 1.14.13
  • convert 2.1.1 [charcode typed_data]
  • coverage 0.14.0 [args logging package_config path source_maps stack_trace vm_service]
  • crypto 2.1.5 [collection convert typed_data]
  • csslib 0.16.2 [source_span]
  • fake_async 1.1.0 [clock collection]
  • ffi 0.1.3
  • file 5.2.1 [intl meta path]
  • file_picker 1.13.3 [flutter flutter_plugin_android_lifecycle file_picker_platform_interface]
  • file_picker_platform_interface 1.3.1 [flutter plugin_platform_interface]
  • firebase 7.3.0 [http http_parser js]
  • firebase_analytics_platform_interface 1.0.3 [flutter meta]
  • firebase_analytics_web 0.1.1 [flutter flutter_web_plugins firebase firebase_analytics_platform_interface meta]
  • firebase_auth_platform_interface 1.1.8 [flutter meta plugin_platform_interface]
  • firebase_auth_web 0.1.3+1 [firebase_auth_platform_interface flutter flutter_web_plugins firebase http_parser meta js]
  • firebase_core_platform_interface 1.0.4 [flutter meta plugin_platform_interface quiver]
  • firebase_core_web 0.1.1+2 [firebase firebase_core_platform_interface flutter flutter_web_plugins meta js]
  • flare_dart 2.3.4
  • flare_flutter 2.0.6 [flutter flare_dart meta]
  • flare_loading 2.1.1 [flare_flutter flutter]
  • flutter_blurhash 0.5.0 [flutter meta]
  • flutter_cache_manager 1.4.1 [flutter path_provider uuid http path sqflite pedantic clock file rxdart]
  • flutter_keyboard_visibility 3.2.2 [flutter]
  • flutter_plugin_android_lifecycle 1.0.8 [flutter]
  • flutter_web_plugins 0.0.0 [flutter characters collection meta typed_data vector_math]
  • fuchsia_remote_debug_protocol 0.0.0 [json_rpc_2 process web_socket_channel flutter_test flutter_driver archive args async boolean_selector charcode clock collection convert crypto fake_async file intl matcher meta path platform pub_semver source_span stack_trace stream_channel string_scanner sync_http term_glyph test_api typed_data vector_math vm_service_client webdriver]
  • glob 1.2.0 [async collection node_io path pedantic string_scanner]
  • google_maps_flutter_platform_interface 1.0.4 [flutter meta plugin_platform_interface stream_transform]
  • html 0.14.0+3 [csslib source_span]
  • http 0.12.2 [http_parser path pedantic]
  • http_multi_server 2.2.0 [async]
  • http_parser 3.1.4 [charcode collection source_span string_scanner typed_data]
  • image_picker_platform_interface 1.1.0 [flutter meta http plugin_platform_interface]
  • io 0.3.4 [charcode meta path string_scanner]
  • js 0.6.2
  • json_annotation 3.0.1
  • json_rpc_2 2.2.1 [stack_trace stream_channel]
  • location_platform_interface 1.0.0 [flutter meta plugin_platform_interface]
  • location_web 1.0.0 [flutter flutter_web_plugins location_platform_interface http_parser meta js]
  • logging 0.11.4
  • markdown 2.1.8 [args charcode meta]
  • marker 0.1.0 [markdown]
  • matcher 0.12.8 [stack_trace]
  • maybe_just_nothing 0.3.1
  • meta 1.1.8
  • mime 0.9.7
  • moor 3.3.1 [meta convert collection synchronized pedantic sqlite3]
  • nested 0.0.4 [flutter]
  • node_interop 1.1.1 [js]
  • node_io 1.1.1 [node_interop path]
  • node_preamble 1.4.12
  • octo_image 0.2.1 [flutter flutter_blurhash]
  • open_iconic_flutter 0.3.0 [flutter]
  • package_config 1.9.3 [path charcode]
  • path 1.7.0
  • path_provider 1.6.14 [flutter path_provider_platform_interface path_provider_macos path_provider_linux]
  • path_provider_linux 0.0.1+2 [path xdg_directories path_provider_platform_interface flutter]
  • path_provider_macos 0.0.4+3 [flutter]
  • path_provider_platform_interface 1.0.3 [flutter meta platform plugin_platform_interface]
  • pedantic 1.9.0
  • photo_view 0.10.2 [flutter]
  • platform 2.2.1
  • platform_detect 1.4.0 [meta pub_semver]
  • plugin_platform_interface 1.0.2 [meta]
  • pointycastle 1.0.2
  • pool 1.4.0 [async stack_trace]
  • process 3.0.13 [file intl meta path platform]
  • pub_cache 0.2.3 [path pub_semver yaml]
  • quiver_hashcode 2.0.0
  • random_string 2.1.0
  • resource 2.1.7 [typed_data]
  • shared_preferences_linux 0.0.2+2 [file flutter meta path path_provider_linux shared_preferences_platform_interface]
  • shared_preferences_macos 0.0.1+10 [shared_preferences_platform_interface flutter]
  • shared_preferences_platform_interface 1.0.4 [meta flutter]
  • shared_preferences_web 0.1.2+7 [shared_preferences_platform_interface flutter flutter_web_plugins meta]
  • shelf 0.7.9 [async collection http_parser path stack_trace stream_channel]
  • shelf_packages_handler 2.0.0 [path shelf shelf_static]
  • shelf_static 0.2.8 [convert http_parser mime path shelf]
  • shelf_web_socket 0.2.3 [shelf web_socket_channel stream_channel]
  • sky_engine 0.0.99
  • source_map_stack_trace 2.0.0 [path stack_trace source_maps]
  • source_maps 0.10.9 [source_span]
  • source_span 1.7.0 [charcode collection meta path term_glyph]
  • sqflite 1.3.1+1 [flutter sqflite_common path]
  • sqflite_common 1.0.2+1 [synchronized path meta]
  • sqlite3 0.1.4 [collection ffi meta]
  • sqlite3_flutter_libs 0.2.0
  • stack_trace 1.9.5 [path]
  • stream_channel 2.0.0 [async]
  • stream_chat 0.2.3+3 [flutter json_annotation shared_preferences logging dio web_socket_channel uuid async stream_channel moor path_provider path rxdart collection sqlite3_flutter_libs]
  • stream_transform 1.2.0
  • string_scanner 1.0.5 [charcode meta source_span]
  • sync_http 0.2.0
  • synchronized 2.2.0+2
  • term_glyph 1.1.0
  • test_api 0.2.17 [async boolean_selector collection meta path source_span stack_trace stream_channel string_scanner term_glyph matcher]
  • test_core 0.3.10 [analyzer async args boolean_selector collection coverage glob io meta package_config path pedantic pool source_map_stack_trace source_maps source_span stack_trace stream_channel vm_service yaml matcher test_api]
  • tool_base 1.9.5+3 [archive file platform process pub_cache]
  • tool_mobile 1.9.5+1 [tool_base]
  • typed_data 1.2.0 [collection]
  • url_launcher_linux 0.0.1+1 [flutter]
  • url_launcher_macos 0.0.1+7 [flutter]
  • url_launcher_platform_interface 1.0.8 [flutter meta plugin_platform_interface]
  • url_launcher_web 0.1.3 [url_launcher_platform_interface platform_detect flutter flutter_web_plugins meta]
  • uuid 2.2.2 [crypto convert]
  • vector_math 2.0.8
  • version_manipulation 0.0.2 [pub_semver]
  • video_player 0.10.12+2 [meta video_player_platform_interface video_player_web flutter]
  • video_player_platform_interface 2.1.1 [flutter meta]
  • video_player_web 0.1.3+2 [flutter flutter_web_plugins meta video_player_platform_interface]
  • vin_decoder 0.1.2 [meta basic_utils http random_string]
  • vm_service 4.2.0 [meta]
  • vm_service_client 0.2.6+2 [async collection json_rpc_2 pub_semver source_span stack_trace stream_channel web_socket_channel]
  • wakelock 0.1.4+2 [flutter]
  • watcher 0.9.7+15 [async path pedantic]
  • web_socket_channel 1.1.0 [async crypto stream_channel]
  • webdriver 2.1.2 [archive matcher path stack_trace sync_http]
  • webkit_inspection_protocol 0.7.3 [logging]
  • xdg_directories 0.1.0 [path process flutter]
  • yaml 2.2.1 [charcode collection string_scanner source_span]
  • yaml_edit 1.0.1 [meta quiver_hashcode yaml source_span collection]```

@rubenvereecken rubenvereecken added Needs Attention This issue needs maintainer attention. type: bug Something isn't working labels Sep 5, 2020
@rubenvereecken
Copy link
Author

Maybe someone else can learn from my mistakes. This was an "entitlement" problem in XCode. I had already ticked "Remote notifications" etc. Not enough. You also need to click "Capability +" in the top-left corner and add Push Notifications. If you use Schemes -- still not enough. You might want to set it up separately for each scheme, because adding the capability adds an aps-environment variable in some file somewhere which is first set to development. I just let XCode make all the files then took it from there with a text editor to set the relevant files to production, which XCode wouldn't do even with an "App Store" (production/distribution) provisioning profile selected.

@firebase firebase locked and limited conversation to collaborators Oct 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Needs Attention This issue needs maintainer attention. type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant