Skip to content

🐛 [firebase_messaging][firebase_auth] Data-only messages not received in iOS. Never fires anything in onMessage #3395

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

Closed
acoutts opened this issue Aug 29, 2020 · 23 comments
Labels
impact: crowd Affects many people, though not necessarily a specific customer with an assigned label. (P2) platform: ios Issues / PRs which are specifically for iOS. plugin: auth type: bug Something isn't working

Comments

@acoutts
Copy link

acoutts commented Aug 29, 2020

Bug report

Describe the bug
On iOS, it appears that sending a data-only message to FCM is not received at the device, even though the message is successfully sent according to FCM rest API.

This is on a real iOS device and not a simulator. Push notifications are otherwise working great - it's just data-only messages that are not doing anything in iOS. I have full functionality with onLaunch, onMessage, and onResume on iOS and Android, as long as it's a notification. Data-only is only being received on Android though.

Steps to reproduce

Note: in the following examples I've redacted the token.

This message is not received in iOS:

{
    "message": {
        "token": "---",
        "data": {
            "foo": "bar"
        }
    }
}

This one does work as expected:

{
    "message": {
        "token": "---",
        "notification": {
            "title": "test"
            "body": "test"
        },
        "data": {
            "foo": "bar"
        }
    }
}

It appears there's no way to receive data-only messages in iOS. It doesn't matter if the app is foregrounded or backgrounded- onMessage is never fired.

Expected behavior

iOS should work with data messages exactly as it does in Android.


Additional context

firebase_core: ^0.5.0
firebase_messaging: ^7.0.0

Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand
[✓] Flutter (Channel dev, 1.21.0-7.0.pre, on Mac OS X 10.15.6 19G73, locale en-US)
    • Flutter version 1.21.0-7.0.pre at /Users/andrewcoutts/Projects/flutter
    • Framework revision 5a6dfa35ca (4 weeks ago), 2020-08-03 10:33:07 -0700
    • Engine revision 083282e33b
    • Dart version 2.10.0 (build 2.10.0-4.0.dev 365525432a)

 
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at /Users/andrewcoutts/Library/Android/sdk
    • Platform android-30, build-tools 29.0.3
    • ANDROID_HOME = /Users/andrewcoutts/Library/Android/sdk
    • 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)
    • All Android licenses accepted.

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

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] 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.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.12.1

[✓] Connected device (6 available)
    • Android SDK built for x86 64 (mobile) • emulator-5554                        • android-x64    • Android 10 (API 29) (emulator)
    • xff0c-se (mobile)                     • 00008030-0016283036BB802E            • ios            • iOS 13.6
    • iPhone 11 Pro Max (mobile)            • 29CD7BB2-300D-4F6B-BDC2-3130066F7F95 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-13-6 (simulator)
    • iPhone SE (2nd generation) (mobile)   • 476F4C67-CC2F-49FF-9145-13ABBECEECA5 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-13-6 (simulator)
    • Web Server (web)                      • web-server                           • web-javascript • Flutter Tools
    • Chrome (web)                          • chrome                               • web-javascript • Google Chrome 84.0.4147.135
    ! Error: xff0c-se is busy: Processing cache files from device. Xcode will continue when xff0c-se is finished. (code -10)

• No issues found!

Flutter dependencies

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

Click To Expand
Dart SDK 2.10.0-4.0.dev.flutter-365525432a
Flutter SDK 1.21.0-7.0.pre
bottlepay 1.0.0+1

dependencies:
- after_layout 1.0.7+2 [flutter]
- app_settings 4.0.3 [flutter]
- basic_utils 2.6.2 [http logging json_annotation pointycastle asn1lib convert crypto]
- bolt11_decoder 0.0.0 [bech32 decimal fixnum]
- bottlepay_apis 0.2.7 [protobuf grpc]
- btc_address_validate 0.1.1 [bech32 base58check equatable]
- cached_network_image 2.2.0+1 [flutter flutter_cache_manager]
- camera 0.5.9 [flutter]
- charts_flutter 0.9.0 [charts_common collection flutter intl logging meta]
- connectivity 0.4.9+2 [flutter meta connectivity_platform_interface connectivity_macos connectivity_for_web]
- corsac_jwt 0.2.2 [asn1lib logging pointycastle rsa_pkcs crypto]
- countdown_flutter 0.1.2 [flutter]
- crypto_keys 0.1.3 [pointycastle meta built_value built_collection]
- cupertino_icons 0.1.3
- data_connection_checker 0.3.4
- decimal 0.3.5 [rational]
- device_info 0.4.2+6 [flutter]
- dio 3.0.10 [http_parser path]
- dotted_border 1.0.6 [flutter path_drawing]
- easy_localization 2.3.3 [flutter intl shared_preferences args path flutter_localizations]
- esys_flutter_share 1.0.2 [flutter path_provider]
- exif 1.0.3 [args collection convert sprintf]
- firebase_auth 0.18.0+1 [meta firebase_core firebase_core_platform_interface firebase_auth_platform_interface firebase_auth_web flutter]
- firebase_core 0.5.0 [firebase_core_platform_interface flutter quiver meta firebase_core_web]
- firebase_crashlytics 0.1.4+1 [flutter stack_trace]
- firebase_messaging 7.0.0 [meta platform flutter firebase_core]
- firebase_ml_vision 0.9.6+2 [flutter]
- firebase_remote_config 0.4.0 [flutter firebase_core]
- fixnum 0.10.11
- flare_flutter 2.0.6 [flutter flare_dart meta]
- flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine]
- flutter_acquireio 0.0.5 [flutter]
- flutter_android_notification_channel 0.0.1 [flutter]
- flutter_cache_manager 1.4.1 [flutter path_provider uuid http path sqflite pedantic clock file rxdart]
- flutter_custom_tabs 0.6.0 [flutter url_launcher]
- 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_libphonenumber 0.3.7 [flutter devicelocale]
- flutter_local_notifications 1.4.4+4 [flutter platform flutter_local_notifications_platform_interface]
- flutter_localizations 0.0.0 [flutter intl characters collection meta path typed_data vector_math]
- flutter_mobx 1.1.0+2 [mobx flutter]
- flutter_screenutil 1.1.0 [flutter]
- flutter_secure_storage 3.3.3 [meta flutter]
- flutter_showtime 0.1.1 [flutter]
- flutter_slidable 0.5.5 [flutter]
- flutter_string_encryption 0.3.1 [flutter]
- flutter_sumsub_sdk 0.0.2 [flutter]
- flutter_svg 0.18.0 [path_drawing xml vector_math meta flutter]
- 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]
- flutter_vibrate 1.0.1 [flutter]
- giphy_client 0.2.0 [meta http]
- giphy_picker 1.0.4 [flutter giphy_client http flutter_staggered_grid_view random_color]
- grpc 2.2.0 [async crypto googleapis_auth meta http http2]
- http 0.12.2 [http_parser path pedantic]
- image 2.1.14 [archive xml]
- image_cropper 1.3.0 [flutter]
- image_picker 0.6.7+4 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface]
- intent 1.4.0 [flutter]
- intl 0.16.1 [path]
- jose 0.2.1+1 [crypto_keys meta typed_data x509 http_extensions_cache http_extensions http asn1lib]
- json_serializable 3.4.0 [analyzer build build_config json_annotation meta path source_gen]
- local_auth 0.6.3 [flutter meta intl platform flutter_plugin_android_lifecycle]
- logger 0.9.2
- lottie 0.5.1 [flutter archive characters charcode collection logging meta path vector_math]
- mobx 1.2.1+2 [meta]
- mobx_codegen 1.1.0+1 [analyzer build build_resolvers meta mobx path source_gen]
- mockito 4.1.1 [collection matcher meta test_api]
- notification_permissions 0.4.7 [flutter]
- oktoast 2.3.2 [flutter]
- package_info 0.4.1 [flutter]
- path 1.8.0-nullsafety
- path_provider 1.6.11 [flutter path_provider_platform_interface path_provider_macos path_provider_linux]
- pedantic 1.10.0-nullsafety
- permission_handler 5.0.1+1 [flutter meta permission_handler_platform_interface]
- provider 4.3.2+1 [flutter nested collection]
- qr 1.3.0 [meta]
- receive_sharing_intent 1.3.5 [flutter]
- retry 3.0.1
- shared_preferences 0.5.8 [meta flutter shared_preferences_platform_interface shared_preferences_linux shared_preferences_macos shared_preferences_web]
- silent_image_crop 0.0.1 [flutter]
- test 1.16.0-nullsafety.1 [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]
- timeago 2.0.27
- transparent_image 1.0.0
- unique_identifier 0.0.3 [flutter]
- url_launcher 5.5.0 [flutter url_launcher_platform_interface url_launcher_web url_launcher_linux url_launcher_macos]
- uuid 2.2.0 [crypto convert]

dev dependencies:
- build_runner 1.10.2 [args async build build_config build_daemon build_resolvers build_runner_core code_builder collection crypto dart_style glob graphs http_multi_server io js logging meta mime path pedantic pool pub_semver pubspec_parse shelf shelf_web_socket stack_trace stream_transform timing watcher web_socket_channel yaml]

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.5.0-nullsafety [collection]
- base58check 1.0.1 [crypto collection]
- bech32 0.1.2 [convert]
- boolean_selector 2.1.0-nullsafety [source_span string_scanner]
- build 1.3.0 [analyzer async convert crypto logging meta path glob]
- build_config 0.4.2 [checked_yaml json_annotation meta path pubspec_parse yaml]
- build_daemon 2.1.4 [built_collection built_value http_multi_server logging pedantic path pool shelf shelf_web_socket stream_transform watcher web_socket_channel]
- build_resolvers 1.3.11 [analyzer build crypto graphs logging path package_config pub_semver]
- build_runner_core 6.0.1 [async build build_config build_resolvers collection convert crypto glob graphs json_annotation logging meta path package_config pedantic pool timing watcher yaml]
- built_collection 4.3.2 [collection quiver]
- built_value 7.1.0 [built_collection collection fixnum quiver]
- characters 1.1.0-nullsafety.2
- charcode 1.2.0-nullsafety
- charts_common 0.9.0 [collection intl logging meta vector_math]
- checked_yaml 1.0.2 [json_annotation source_span yaml]
- cli_util 0.2.0 [path]
- clock 1.1.0-nullsafety
- code_builder 3.4.1 [built_collection built_value collection matcher meta]
- collection 1.15.0-nullsafety.2
- connectivity_for_web 0.3.1+2 [connectivity_platform_interface flutter_web_plugins flutter]
- connectivity_macos 0.1.0+4 [flutter]
- connectivity_platform_interface 1.0.6 [flutter meta plugin_platform_interface]
- 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]
- dart_style 1.3.6 [analyzer args path source_span]
- devicelocale 0.3.1 [flutter]
- equatable 1.2.3 [collection meta]
- fake_async 1.1.0-nullsafety [clock collection]
- file 5.2.1 [intl meta path]
- firebase 7.3.0 [http http_parser js]
- firebase_auth_platform_interface 2.0.1 [flutter meta firebase_core plugin_platform_interface]
- firebase_auth_web 0.3.0+1 [flutter flutter_web_plugins firebase meta http_parser intl firebase_core firebase_auth_platform_interface js]
- firebase_core_platform_interface 2.0.0 [flutter meta plugin_platform_interface quiver]
- firebase_core_web 0.2.0 [firebase firebase_core_platform_interface flutter flutter_web_plugins meta js]
- flare_dart 2.3.4
- flutter_local_notifications_platform_interface 1.0.1 [flutter plugin_platform_interface]
- flutter_plugin_android_lifecycle 1.0.8 [flutter]
- flutter_staggered_grid_view 0.3.2 [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]
- googleapis_auth 0.2.12 [crypto http]
- graphs 0.2.0
- html 0.14.0+3 [csslib source_span]
- http2 1.0.0
- http_extensions 0.1.2 [meta http]
- http_extensions_cache 0.1.3 [meta http uuid http_extensions logging]
- 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.3-nullsafety
- json_annotation 3.0.1
- json_rpc_2 2.2.1 [stack_trace stream_channel]
- logging 0.11.4
- matcher 0.12.10-nullsafety [stack_trace]
- meta 1.3.0-nullsafety.2
- mime 0.9.7
- nested 0.0.4 [flutter]
- node_interop 1.1.1 [js]
- node_io 1.1.1 [node_interop path]
- node_preamble 1.4.12
- package_config 1.9.3 [path charcode]
- path_drawing 0.4.1 [vector_math meta path_parsing flutter]
- path_parsing 0.1.4 [vector_math meta]
- 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]
- permission_handler_platform_interface 2.0.1 [flutter meta plugin_platform_interface]
- petitparser 3.1.0 [meta]
- 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.5.0-nullsafety [async stack_trace]
- process 3.0.13 [file intl meta path platform]
- protobuf 1.0.1 [fixnum]
- pub_semver 1.4.4 [collection]
- pubspec_parse 0.1.5 [checked_yaml json_annotation pub_semver yaml]
- quiver 2.1.3 [matcher meta]
- random_color 1.0.5 [flutter]
- rational 0.3.8
- rsa_pkcs 1.1.3 [asn1lib]
- rxdart 0.24.1
- shared_preferences_linux 0.0.2+1 [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_gen 0.9.6 [analyzer async build dart_style glob meta path pedantic source_span]
- source_map_stack_trace 2.1.0-nullsafety.1 [path stack_trace source_maps]
- source_maps 0.10.10-nullsafety [source_span]
- source_span 1.8.0-nullsafety [charcode collection path term_glyph]
- sprintf 4.1.0
- sqflite 1.3.1 [flutter sqflite_common path]
- sqflite_common 1.0.2+1 [synchronized path meta]
- stack_trace 1.10.0-nullsafety [path]
- stream_channel 2.1.0-nullsafety [async]
- stream_transform 1.2.0
- string_scanner 1.1.0-nullsafety [charcode source_span]
- sync_http 0.2.0
- synchronized 2.2.0+2
- term_glyph 1.2.0-nullsafety
- test_api 0.2.19-nullsafety [async boolean_selector collection meta path source_span stack_trace stream_channel string_scanner term_glyph matcher]
- test_core 0.3.12-nullsafety.1 [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]
- timing 0.1.1+2 [json_annotation]
- typed_data 1.3.0-nullsafety.2 [collection]
- url_launcher_linux 0.0.1+1 [flutter]
- url_launcher_macos 0.0.1+7 [flutter]
- url_launcher_platform_interface 1.0.7 [flutter meta plugin_platform_interface]
- url_launcher_web 0.1.2+1 [url_launcher_platform_interface platform_detect flutter flutter_web_plugins meta]
- vector_math 2.1.0-nullsafety.2
- 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]
- 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]
- x509 0.1.3 [asn1lib quiver crypto_keys]
- xdg_directories 0.1.2 [meta path process]
- xml 4.4.1 [collection convert meta petitparser]
- yaml 2.2.1 [charcode collection string_scanner source_span]

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

acoutts commented Aug 30, 2020

I notice this is printing in Xcode whenever a data message does come in (though it never makes it to onMessage):

Warning: Application delegate received call to -application:didReceiveRemoteNotification:fetchCompletionHandler: but the completion handler was never called.

@acoutts
Copy link
Author

acoutts commented Aug 30, 2020

Upon testing the included example app, it appears to work as expected so I can only suspect mine is broken because of one of the following packages I'm using:

  • firebase_auth: ^0.18.0+1
  • flutter_local_notifications: ^1.4.4+4

I notice some really odd behavior after adding print statements throughout the firebase_messaging plugin. I am not seeing this method execute ever:

  • didReceiveRemoteNotification

@acoutts
Copy link
Author

acoutts commented Aug 30, 2020

Alright the issue is looking to be in firebase_auth. The remote notification is being swallowed up by didReceiveRemoteNotification, returning no and not calling the completion handler:

In FLTFirebaseAuthPlugin.m:

#if TARGET_OS_IPHONE
- (BOOL)application:(UIApplication *)application
    didReceiveRemoteNotification:(NSDictionary *)notification
          fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler {
  if ([[FIRAuth auth] canHandleNotification:notification]) {
    completionHandler(UIBackgroundFetchResultNoData);
    return YES;
  }
  return NO;
}

Then this is printed:
Warning: Application delegate received call to -application:didReceiveRemoteNotification:fetchCompletionHandler: but the completion handler was never called.

Data messages seem to work in my app without firebase auth added, but as soon as I add firebase_auth to my pubspec (before even importing it anywhere in my project), it's then broken.

@acoutts acoutts changed the title 🐛 [firebase_messaging] Data-only messages not received in iOS. Never fires anything in onMessage 🐛 [firebase_messaging][firebase_auth] Data-only messages not received in iOS. Never fires anything in onMessage Aug 30, 2020
@acoutts
Copy link
Author

acoutts commented Aug 30, 2020

I'm confident now the issue is firebase_auth. It appears 0.18.0+1 is broken.

I'm seeing some really strange versioning behavior too. None of the recent commits on firebase_auth seem to compile/work until ba7124b5a0b24b76587cfdb6bb36afcb2427d792. So checking that out locally and adding to my pubspec:

➜  ios git:(ba7124b5) ✗ git status
HEAD detached at ba7124b5
  firebase_auth:
    path: ../flutterfire/packages/firebase_auth/firebase_auth

It still doesn't work (same error as before).

If I add a single NSLog statement inside didReceiveRemoteNotification then magically everything works now.
If I try checking out ba7124b5 with git, it doesn't work:

  firebase_auth:
    git:
      url: https://github.com/FirebaseExtended/flutterfire.git
      path: packages/firebase_auth/firebase_auth
      ref: ba7124b5

It just goes back to printing the same error as before:

Warning: Application delegate received call to -application:didReceiveRemoteNotification:fetchCompletionHandler: but the completion handler was never called.

This has been incredibly frustrating as I've spent 8 hours now trying to pin this down.

I even tried to really clean things out, but no luck:

  • Deleted app from phone
  • rm -rf ~/.pub-cache
  • rm -rf ios/Pods/*
  • rm ios/Podfile.lock
  • rm -rf ~/Library/Developer/Xcode/DerivedData/*
  • flutter clean
  • cmd + shift + K in Xcode to clean the project
  • flutter pub get
  • cd ios && pod install
  • fresh build again

Does anybody currently have firebase auth and messaging working together in the same project?

@acoutts
Copy link
Author

acoutts commented Aug 30, 2020

cc @Salakar

@blaneyneil
Copy link

after moving to:

firebase_auth: ^0.18.0+1
firebase_messaging: "^7.0.0"

my onMessage foreground triggering is failing too. however, i'm not sending data messages but rather notifications.

@acoutts
Copy link
Author

acoutts commented Aug 31, 2020

Here's a makefile target that can help you stay sane while debugging iOS issues given the number of things that can be cached:

deep-clean-ios:
	rm -rf ~/.pub-cache
	rm -rf ios/Pods/*
	rm -f ios/Podfile.lock
	rm -rf ~/Library/Developer/Xcode/DerivedData/*
	flutter clean

Despite the weird behavior I had above where I had to add that print statement, now just checking out the repo locally:

git clone https://github.com/FirebaseExtended/flutterfire.git
git checkout ba7124b5a0b24b76587cfdb6bb36afcb2427d792

Then setting my pubspec:

  firebase_auth:
    path: ../flutterfire/packages/firebase_auth/firebase_auth

I see data messages working now. So it appears things are broken in the 0.18.0+1 release, but in some recent commit since that release it's been fixed.
The commit ba7124b5a0b24b76587cfdb6bb36afcb2427d792 is the last time firebase_auth compiled / worked. Seems like they're reworking some things in the web side of the lib and that's in-progress.

But I'm noticing some inconsistent behavior:

  firebase_auth:
    git:
      url: https://github.com/FirebaseExtended/flutterfire.git
      path: packages/firebase_auth/firebase_auth
      ref: ba7124b5a0b24b76587cfdb6bb36afcb2427d792

Doesn't work. It just prints this again when I receive a data message:

Application delegate received call to -application:didReceiveRemoteNotification:fetchCompletionHandler: but the completion handler was never called.

From a pub / flutter perspective, why is there different behavior when I locally checkout the repo at a specific commit, vs specifying the exact same thing in the pubspec? Could it be something to do with the monorepo setup on flutterfire?

@acoutts
Copy link
Author

acoutts commented Aug 31, 2020

after moving to:

firebase_auth: ^0.18.0+1
firebase_messaging: "^7.0.0"

my onMessage foreground triggering is failing too. however, i'm not sending data messages but rather notifications.

What previous versions were you using that worked? This is blocking critical functionality in our production app now and I would love to find a working combo.

@acoutts
Copy link
Author

acoutts commented Aug 31, 2020

When I try to go back to 0.16.1+2, it's now saying the version doesn't exist:

Because bottlepay depends on firebase_auth ^0.16.1+2 which doesn't match any versions, version solving failed.

Have the old versions now been removed and we can't downgrade?

@darshankawar darshankawar added plugin: auth platform: ios Issues / PRs which are specifically for iOS. and removed Needs Attention This issue needs maintainer attention. labels Aug 31, 2020
@acoutts
Copy link
Author

acoutts commented Aug 31, 2020

I found a workaround for anyone stuck like me. I can't believe this is the only way that works, but you need to do the following:

  • Clone flutterfire to your computer, checkout commit ba7124b5a0b24b76587cfdb6bb36afcb2427d792.
  • Copy the packages/firebase_auth/firebase_auth folder into your project.
  • Update your project's pubspec like this:
  firebase_auth:
    path: your/path/to/firebase_auth
  firebase_messaging: ^7.0.0
  • Everything will work again.

The annoying thing is that you need to commit the firebase_auth files into your project if you want it to work in CI or on anybody else's environment. This must be some bug in pub that trying to point to the flutterfire git doesn't resolve the right files.

Make sure to add a .gitignore file inside your locally-included firebase_auth folder to ignore the example folder, or else you'll commit 300mb+ of files into your repo that you don't need.

example/

Or, just delete the example folder after you copy firebase_auth in before you commit it up.

@acoutts
Copy link
Author

acoutts commented Aug 31, 2020

Alright while that fixes firebases_messaging, it breaks the method swizzling because now the message never makes it to firebase_auth, so using the commit above is still broken. Here's what happens when I try phone auth now:

Phone number verification failed. Code: notification-not-forwarded. Message: If app delegate swizzling is disabled, remote notifications received by UIApplicationDelegate need to be forwarded to FIRAuth's canHandleNotificaton: method.

The data message instead comes in the firebase_messaging onMessage handler:

onMessage: {com.google.firebase.auth: {warning: This fake notification should be forwarded to Firebase Auth.}}

I'm going to try to get this to work now with swizzling disabled and see if I can at least make my app functional again..

@acoutts
Copy link
Author

acoutts commented Aug 31, 2020

Disabling method swizzling and using the below in my AppDelegate.swift, fingers crossed but this seems to fix it so that both auth and messaging are functioning as expected. It would be nice to use swizzling but this isn't the end of the world if this is required to make the two work.

pubspec.yaml:

  firebase_auth: ^0.18.0+1
  firebase_core: ^0.5.0
  firebase_messaging: ^7.0.0

ios/Runner/Info.plist:

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

AppDelegate.swift:

import UIKit
import Flutter
import FirebaseAuth
import FirebaseMessaging

@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
        }
        
        GeneratedPluginRegistrant.register(with: self)
        return super.application(application, didFinishLaunchingWithOptions: launchOptions)
    }
    
    // https://firebase.google.com/docs/auth/ios/phone-auth#appendix:-using-phone-sign-in-without-swizzling
    // https://firebase.google.com/docs/cloud-messaging/ios/client#token-swizzle-disabled
    override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        // Pass device token to auth
        Auth.auth().setAPNSToken(deviceToken, type: .unknown)
        
        // Pass device token to messaging
        Messaging.messaging().apnsToken = deviceToken
        
        return super.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)
    }
    
    // https://firebase.google.com/docs/auth/ios/phone-auth#appendix:-using-phone-sign-in-without-swizzling
    // https://firebase.google.com/docs/cloud-messaging/ios/receive#handle-swizzle
    override func application(_ application: UIApplication,
                              didReceiveRemoteNotification notification: [AnyHashable : Any],
                              fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        // Handle the message for firebase auth phone verification
        if Auth.auth().canHandleNotification(notification) {
            completionHandler(.noData)
            return
        }
        
        // Handle it for firebase messaging analytics
        if ((notification["gcm.message_id"]) != nil) {
            Messaging.messaging().appDidReceiveMessage(notification)
        }
        
        return super.application(application, didReceiveRemoteNotification: notification, fetchCompletionHandler: completionHandler)
    }
    
    // https://firebase.google.com/docs/auth/ios/phone-auth#appendix:-using-phone-sign-in-without-swizzling
    override func application(_ application: UIApplication, open url: URL,
                              options: [UIApplication.OpenURLOptionsKey : Any]) -> Bool {
        // Handle auth reCAPTCHA when silent push notifications aren't available
        if Auth.auth().canHandle(url) {
            return true
        }
        
        return super.application(application, open: url, options: options)
    }
}

@acoutts
Copy link
Author

acoutts commented Aug 31, 2020

@blaneyneil can you try that above and see if it works for you?

@blaneyneil
Copy link

this does indeed work - awesome job. onMessage is triggered again, and app-closed pushes are handled. putting it thru testing with auth shortly.

@guoguoguilai
Copy link

Disabling method swizzling and using the below in my AppDelegate.swift, fingers crossed but this seems to fix it so that both auth and messaging are functioning as expected. It would be nice to use swizzling but this isn't the end of the world if this is required to make the two work.

pubspec.yaml:

  firebase_auth: ^0.18.0+1
  firebase_core: ^0.5.0
  firebase_messaging: ^7.0.0

ios/Runner/Info.plist:

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

AppDelegate.swift:

import UIKit
import Flutter
import FirebaseAuth
import FirebaseMessaging

@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
        }
        
        GeneratedPluginRegistrant.register(with: self)
        return super.application(application, didFinishLaunchingWithOptions: launchOptions)
    }
    
    // https://firebase.google.com/docs/auth/ios/phone-auth#appendix:-using-phone-sign-in-without-swizzling
    // https://firebase.google.com/docs/cloud-messaging/ios/client#token-swizzle-disabled
    override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        // Pass device token to auth
        Auth.auth().setAPNSToken(deviceToken, type: .unknown)
        
        // Pass device token to messaging
        Messaging.messaging().apnsToken = deviceToken
        
        return super.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)
    }
    
    // https://firebase.google.com/docs/auth/ios/phone-auth#appendix:-using-phone-sign-in-without-swizzling
    // https://firebase.google.com/docs/cloud-messaging/ios/receive#handle-swizzle
    override func application(_ application: UIApplication,
                              didReceiveRemoteNotification notification: [AnyHashable : Any],
                              fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        // Handle the message for firebase auth phone verification
        if Auth.auth().canHandleNotification(notification) {
            completionHandler(.noData)
            return
        }
        
        // Handle it for firebase messaging analytics
        if ((notification["gcm.message_id"]) != nil) {
            Messaging.messaging().appDidReceiveMessage(notification)
        }
        
        return super.application(application, didReceiveRemoteNotification: notification, fetchCompletionHandler: completionHandler)
    }
    
    // https://firebase.google.com/docs/auth/ios/phone-auth#appendix:-using-phone-sign-in-without-swizzling
    override func application(_ application: UIApplication, open url: URL,
                              options: [UIApplication.OpenURLOptionsKey : Any]) -> Bool {
        // Handle auth reCAPTCHA when silent push notifications aren't available
        if Auth.auth().canHandle(url) {
            return true
        }
        
        return super.application(application, open: url, options: options)
    }
}

Is there any solution for Objective-C?

@acoutts
Copy link
Author

acoutts commented Sep 10, 2020

@guoguoguilai in each of the comments there I linked back to the firebase docs, and in those links you'll find the ObjC examples for what to implement. It's the exact same thing, just in ObjC instead of Swift.

@AmauryTejada
Copy link

this works like a charm!

@Barry0501
Copy link

Disabling method swizzling and using the below in my AppDelegate.swift, fingers crossed but this seems to fix it so that both auth and messaging are functioning as expected. It would be nice to use swizzling but this isn't the end of the world if this is required to make the two work.

pubspec.yaml:

  firebase_auth: ^0.18.0+1
  firebase_core: ^0.5.0
  firebase_messaging: ^7.0.0

ios/Runner/Info.plist:

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

AppDelegate.swift:

import UIKit
import Flutter
import FirebaseAuth
import FirebaseMessaging

@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
        }
        
        GeneratedPluginRegistrant.register(with: self)
        return super.application(application, didFinishLaunchingWithOptions: launchOptions)
    }
    
    // https://firebase.google.com/docs/auth/ios/phone-auth#appendix:-using-phone-sign-in-without-swizzling
    // https://firebase.google.com/docs/cloud-messaging/ios/client#token-swizzle-disabled
    override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        // Pass device token to auth
        Auth.auth().setAPNSToken(deviceToken, type: .unknown)
        
        // Pass device token to messaging
        Messaging.messaging().apnsToken = deviceToken
        
        return super.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)
    }
    
    // https://firebase.google.com/docs/auth/ios/phone-auth#appendix:-using-phone-sign-in-without-swizzling
    // https://firebase.google.com/docs/cloud-messaging/ios/receive#handle-swizzle
    override func application(_ application: UIApplication,
                              didReceiveRemoteNotification notification: [AnyHashable : Any],
                              fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        // Handle the message for firebase auth phone verification
        if Auth.auth().canHandleNotification(notification) {
            completionHandler(.noData)
            return
        }
        
        // Handle it for firebase messaging analytics
        if ((notification["gcm.message_id"]) != nil) {
            Messaging.messaging().appDidReceiveMessage(notification)
        }
        
        return super.application(application, didReceiveRemoteNotification: notification, fetchCompletionHandler: completionHandler)
    }
    
    // https://firebase.google.com/docs/auth/ios/phone-auth#appendix:-using-phone-sign-in-without-swizzling
    override func application(_ application: UIApplication, open url: URL,
                              options: [UIApplication.OpenURLOptionsKey : Any]) -> Bool {
        // Handle auth reCAPTCHA when silent push notifications aren't available
        if Auth.auth().canHandle(url) {
            return true
        }
        
        return super.application(application, open: url, options: options)
    }
}

Thank you, it works perfectly. You make my day!!!

@DomingoMG
Copy link

I am getting an error that it is only compatible with iOS 9 onwards.

Captura de pantalla 2020-09-27 a las 18 33 10

@acoutts
Copy link
Author

acoutts commented Sep 27, 2020

@DomingoMG you'll want to bump your project to iOS9 anyways since that changed recently in Flutter 1.22, so everyone has to make that change.

@rubenvereecken
Copy link

You madman you fixed it.

@TahaTesser TahaTesser added the impact: crowd Affects many people, though not necessarily a specific customer with an assigned label. (P2) label Oct 20, 2020
@andersonmendesdev
Copy link

andersonmendesdev commented Nov 2, 2020

Update: Well, as I don't have the firebase authentication package, my notifications should work and are really working, I found out that simulators and emulators don't support push notifications.

[Firebase/Messaging][I-FCM012002] Error in application:didFailToRegisterForRemoteNotificationsWithError: remote notifications are not supported in the simulator

Unless you have xcode from version >= 11.4 that you can simulate push. As said here: medium

My appDelegate was normal with no other code added. I also didn't add the swizzling key. And I am receiving push on ios 14 in a wonderful way, both targeted messages and specific device messages.

api : https://fcm.googleapis.com/fcm/send
{ "notification": { "body": "mybody", "title":"my title" }, "to": "token here" }

@russellwheatley
Copy link
Member

Hey folks, this should work now without needing to disable swizzling as set out in the migration guide. You should be able to receive data payloads on your iOS devices and I have tested on the messaging example to confirm behaviour. Closing this issue for now, will reopen if there is a reproducible bug.

@firebase firebase locked and limited conversation to collaborators Jul 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
impact: crowd Affects many people, though not necessarily a specific customer with an assigned label. (P2) platform: ios Issues / PRs which are specifically for iOS. plugin: auth type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests