flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

🐛 [FIREBASE_AUTH] iOS Phone Auth Failure because App Swizzling is disabled

Open mdalihusain opened this issue 5 years ago • 26 comments

Bug report

Describe the bug Everything was fine until, I moved to firebase_core 0.7.0 and firebase_auth 0.20.0+1. In iOS, OTP is not being sent on using FirebaseAuth.verifyPhoneNumber, the error says - [firebase_auth/notification-not-forwarded] If app delegate swizzling is disabled, remote notifications received by UIApplicationDelegate need to be forwarded to FIRAuth's canHandleNotificaton: method.

Steps to reproduce

Steps to reproduce the behavior:

  1. Use Firebase Core 0.7.0 and FirebaseAuth 0.20.0+1 and firebase messaging 8.0.0-dev.14
  2. Set FirebaseAppDelegateProxyEnabled to False
  3. Try to login user using phone auth, FirebaseAuth.verifyPhoneNumber method.
  4. Get this error - [firebase_auth/notification-not-forwarded] If app delegate swizzling is disabled, remote notifications received by UIApplicationDelegate need to be forwarded to FIRAuth's canHandleNotificaton: method.

Expected behavior

An OTP should have been sent to the User's Phone Number


Additional context

This problem doesn't exist on firebase_core: ^0.5.0+1 and firebase_auth: ^0.18.4+1 and firebase_messaging: ^7.0.3 plugins. But, can't use them due to numerous other issues in them.

Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand
[✓] Flutter (Channel beta, 1.24.0-10.2.pre, on Mac OS X 10.15.5 19F101
    darwin-x64, locale en-IN)
    • Flutter version 1.24.0-10.2.pre at /Users/ali/Downloads/flutter
    • Framework revision 022b333a08 (3 months ago), 2020-11-18 11:35:09 -0800
    • Engine revision 07c1eed46b
    • Dart version 2.12.0 (build 2.12.0-29.10.beta)

[✗] Android toolchain - develop for Android devices
    ✗ Unable to locate Android SDK.
      Install Android Studio from:
      https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK
      components.
      (or visit https://flutter.dev/docs/get-started/install/macos#android-setup
      for detailed instructions).
      If the Android SDK has been installed to a custom location, please use
      `flutter config --android-sdk` to update to that location.


[✓] Xcode - develop for iOS and macOS (Xcode 12.4)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.4, Build version 12D4e
    • CocoaPods version 1.10.1

[!] Android Studio (not installed)
    • Android Studio not found; download from
      https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/macos#android-setup
      for detailed instructions).

[✓] Connected device (1 available)
    • Tariq’s iPad (mobile) • db2c970560eb6407b7af26a1b84d868055d6b68a • ios •
      iOS 14.4

! Doctor found issues in 2 categories.

Flutter dependencies

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

Click To Expand
Dart SDK 2.12.0-29.10.beta
Flutter SDK 1.24.0-10.2.pre
devbhoomi_insider 1.1.0+7

dependencies:
- cached_network_image 2.4.1 [flutter flutter_cache_manager octo_image]
- cloud_firestore 0.16.0 [flutter meta quiver firebase_core firebase_core_platform_interface cloud_firestore_platform_interface cloud_firestore_web]
- crypto 2.1.5 [collection convert typed_data]
- cupertino_icons 1.0.0
- firebase_analytics 7.0.1 [meta flutter firebase_core firebase_analytics_web firebase_analytics_platform_interface]
- firebase_auth 0.20.0+1 [meta firebase_core firebase_core_platform_interface firebase_auth_platform_interface firebase_auth_web flutter]
- firebase_core 0.7.0 [firebase_core_platform_interface flutter quiver meta firebase_core_web]
- firebase_crashlytics 0.4.0+1 [flutter stack_trace firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface]
- firebase_database 6.0.0 [flutter firebase_core]
- firebase_dynamic_links 0.7.0+1 [flutter firebase_core]
- firebase_messaging 8.0.0-dev.14 [meta flutter firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web]
- firebase_remote_config 0.6.0 [flutter firebase_core]
- firebase_storage 7.0.0 [flutter firebase_core firebase_core_platform_interface firebase_storage_web firebase_storage_platform_interface quiver]
- flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine]
- flutter_html 1.0.2 [html csslib css_colors video_player chewie webview_flutter chewie_audio flutter_svg flutter]
- flutter_image_compress 0.7.0 [flutter]
- flutter_launcher_icons 0.8.1 [image args yaml path]
- flutter_mobx 0.3.4+3 [mobx flutter]
- flutter_phoenix 0.1.0 [flutter]
- flutter_share_me 0.9.2 [flutter]
- flutter_signin_button 1.1.0 [flutter font_awesome_flutter]
- fluttertoast 7.1.1 [flutter flutter_web_plugins]
- get_it 5.0.3 [async meta]
- google_fonts 0.3.10 [flutter http path_provider crypto]
- google_sign_in 4.5.6 [google_sign_in_platform_interface flutter meta google_sign_in_web]
- image_cropper 1.3.1 [flutter]
- image_picker 0.6.7+15 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface]
- in_app_update 1.1.15 [flutter]
- marquee_flutter 0.1.4 [flutter]
- mobx 0.3.10 [meta]
- package_info 0.4.3+2 [flutter]
- provider 4.3.2+3 [collection flutter nested]
- screenshot 0.2.0 [path_provider flutter]
- share 0.6.5+4 [meta mime flutter]
- shared_preferences 0.5.12+4 [meta flutter shared_preferences_platform_interface shared_preferences_linux shared_preferences_macos shared_preferences_web shared_preferences_windows]
- sign_in_with_apple 2.5.4 [meta flutter]
- social_share 2.0.5 [flutter path_provider]
- upgrader 2.7.3 [flutter device_info flutter_device_locale http package_info shared_preferences url_launcher version xml]
- url_launcher 5.7.10 [flutter url_launcher_platform_interface url_launcher_web url_launcher_linux url_launcher_macos url_launcher_windows]
- youtube_player_flutter 7.0.0+7 [flutter flutter_inappwebview]

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]
- 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]
- mobx_codegen 0.3.11 [analyzer build meta mobx path source_gen]

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
- async 2.5.0-nullsafety.3 [collection]
- boolean_selector 2.1.0-nullsafety.3 [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.5
- charcode 1.2.0-nullsafety.3
- checked_yaml 1.0.4 [json_annotation source_span yaml]
- chewie 0.9.10 [open_iconic_flutter video_player wakelock flutter]
- chewie_audio 1.0.0+1 [open_iconic_flutter video_player screen flutter]
- cli_util 0.2.0 [path]
- clock 1.1.0-nullsafety.3
- cloud_firestore_platform_interface 3.0.1 [flutter meta collection firebase_core plugin_platform_interface]
- cloud_firestore_web 0.3.0+1 [flutter flutter_web_plugins http_parser meta firebase_core firebase_core_web cloud_firestore_platform_interface js]
- code_builder 3.5.0 [built_collection built_value collection matcher meta]
- collection 1.15.0-nullsafety.5
- convert 2.1.1 [charcode typed_data]
- css_colors 1.0.2 [flutter]
- csslib 0.16.2 [source_span]
- dart_style 1.3.6 [analyzer args path source_span]
- device_info 1.0.0 [flutter device_info_platform_interface]
- device_info_platform_interface 1.0.1 [flutter meta plugin_platform_interface]
- fake_async 1.2.0-nullsafety.3 [clock collection]
- ffi 0.1.3
- file 5.2.1 [intl meta path]
- firebase 7.3.3 [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 3.0.1 [flutter meta firebase_core plugin_platform_interface]
- firebase_auth_web 0.3.2+6 [flutter flutter_web_plugins meta http_parser intl firebase_core firebase_core_web firebase_auth_platform_interface js]
- firebase_core_platform_interface 3.0.1 [flutter meta plugin_platform_interface quiver]
- firebase_core_web 0.2.1+3 [firebase_core_platform_interface flutter flutter_web_plugins meta js]
- firebase_crashlytics_platform_interface 1.1.6 [flutter meta collection firebase_core plugin_platform_interface]
- firebase_messaging_platform_interface 1.0.0-dev.10 [flutter meta firebase_core plugin_platform_interface]
- firebase_messaging_web 0.1.0-dev.5 [flutter flutter_web_plugins meta firebase_core firebase_core_web firebase_messaging_platform_interface js service_worker]
- firebase_storage_platform_interface 1.0.4 [flutter meta collection firebase_core plugin_platform_interface]
- firebase_storage_web 0.1.1+3 [async crypto firebase_core firebase_core_web firebase_storage_platform_interface flutter flutter_web_plugins http js meta]
- fixnum 0.10.11
- flutter_blurhash 0.5.0 [flutter meta]
- flutter_cache_manager 2.0.0 [flutter path_provider uuid http path sqflite pedantic clock file rxdart]
- flutter_device_locale 0.4.0 [flutter flutter_web_plugins plugin_platform_interface]
- flutter_inappwebview 4.0.0+4 [flutter uuid mime]
- flutter_plugin_android_lifecycle 1.0.11 [flutter]
- flutter_svg 0.18.1 [path_drawing xml vector_math meta flutter]
- flutter_web_plugins 0.0.0 [flutter js characters collection meta typed_data vector_math]
- font_awesome_flutter 8.10.1 [flutter]
- glob 1.2.0 [async collection node_io path pedantic string_scanner]
- google_sign_in_platform_interface 1.1.2 [flutter meta quiver]
- google_sign_in_web 0.9.2 [google_sign_in_platform_interface flutter flutter_web_plugins meta js]
- graphs 0.2.0
- html 0.14.0+4 [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 2.1.19 [archive xml meta]
- image_picker_platform_interface 1.1.1 [flutter meta http plugin_platform_interface]
- intl 0.16.1 [path]
- io 0.3.4 [charcode meta path string_scanner]
- js 0.6.3-nullsafety.3
- json_annotation 3.1.1
- logging 0.11.4
- matcher 0.12.10-nullsafety.3 [stack_trace]
- meta 1.3.0-nullsafety.6
- mime 0.9.7
- nested 0.0.4 [flutter]
- node_interop 1.2.1 [js]
- node_io 1.2.0 [file node_interop path]
- octo_image 0.3.0 [flutter flutter_blurhash]
- open_iconic_flutter 0.3.0 [flutter]
- package_config 1.9.3 [path charcode]
- path 1.8.0-nullsafety.3
- path_drawing 0.4.1+1 [vector_math meta path_parsing flutter]
- path_parsing 0.1.4 [vector_math meta]
- path_provider 1.6.24 [flutter path_provider_platform_interface path_provider_macos path_provider_linux path_provider_windows]
- path_provider_linux 0.0.1+2 [path xdg_directories path_provider_platform_interface flutter]
- path_provider_macos 0.0.4+6 [flutter]
- path_provider_platform_interface 1.0.4 [flutter meta platform plugin_platform_interface]
- path_provider_windows 0.0.4+3 [path_provider_platform_interface meta path flutter ffi win32]
- pedantic 1.9.2 [meta]
- petitparser 3.1.0 [meta]
- platform 2.2.1
- plugin_platform_interface 1.0.3 [meta]
- pool 1.4.0 [async stack_trace]
- process 3.0.13 [file intl meta path platform]
- pub_semver 1.4.4 [collection]
- pubspec_parse 0.1.7 [checked_yaml json_annotation pub_semver yaml]
- quiver 2.1.5 [matcher meta]
- rxdart 0.24.1
- screen 0.0.5 [flutter]
- service_worker 0.2.4 [js]
- shared_preferences_linux 0.0.2+4 [file flutter meta path path_provider_linux shared_preferences_platform_interface]
- shared_preferences_macos 0.0.1+11 [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]
- shared_preferences_windows 0.0.1+3 [shared_preferences_platform_interface flutter ffi file meta path path_provider_platform_interface path_provider_windows]
- shelf 0.7.9 [async collection http_parser path stack_trace stream_channel]
- shelf_web_socket 0.2.3 [shelf web_socket_channel stream_channel]
- sky_engine 0.0.99
- source_gen 0.9.7+1 [analyzer async build dart_style glob meta path pedantic source_span]
- source_span 1.8.0-nullsafety.4 [charcode collection path term_glyph]
- sqflite 1.3.2+1 [flutter sqflite_common path]
- sqflite_common 1.0.2+1 [synchronized path meta]
- stack_trace 1.10.0-nullsafety.6 [path]
- stream_channel 2.1.0-nullsafety.3 [async]
- stream_transform 1.2.0
- string_scanner 1.1.0-nullsafety.3 [charcode source_span]
- synchronized 2.2.0+2
- term_glyph 1.2.0-nullsafety.3
- test_api 0.2.19-nullsafety.6 [async boolean_selector collection meta path source_span stack_trace stream_channel string_scanner term_glyph matcher]
- timing 0.1.1+3 [json_annotation]
- typed_data 1.3.0-nullsafety.5 [collection]
- url_launcher_linux 0.0.1+4 [flutter]
- url_launcher_macos 0.0.1+9 [flutter]
- url_launcher_platform_interface 1.0.9 [flutter meta plugin_platform_interface]
- url_launcher_web 0.1.5+1 [url_launcher_platform_interface flutter flutter_web_plugins meta]
- url_launcher_windows 0.0.1+3 [flutter]
- uuid 2.2.2 [crypto convert]
- vector_math 2.1.0-nullsafety.5
- version 1.2.0
- video_player 0.10.12+5 [meta video_player_platform_interface video_player_web flutter]
- video_player_platform_interface 2.2.0 [flutter meta]
- video_player_web 0.1.4+1 [flutter flutter_web_plugins meta video_player_platform_interface]
- wakelock 0.1.4+2 [flutter]
- watcher 0.9.7+15 [async path pedantic]
- web_socket_channel 1.1.0 [async crypto stream_channel]
- webview_flutter 0.3.24 [flutter]
- win32 1.7.4 [ffi]
- xdg_directories 0.1.2 [meta path process]
- xml 4.5.1 [collection convert meta petitparser]
- yaml 2.2.1 [charcode collection string_scanner source_span]

mdalihusain avatar Feb 06 '21 13:02 mdalihusain

Hi @mdalihusain This is because you are using firebase_messaging and phone auth at the same time (which both use notifications). The solution here is exactly what is mentioned in the error you are getting.

If you previously added the FirebaseAppDelegateProxyEnabled key with a false value to your Info.plist to disable swizzling; you can now remove it, the plugin now supports multiple delegates and will internally forward to any other plugins that may have previously registered a delegate.

You need to set up method swizzling to allow for multiple delegates (see https://github.com/FirebaseExtended/flutterfire/issues/1102). Does this solve the issue for you? Thank you

markusaksli-nc avatar Feb 08 '21 12:02 markusaksli-nc

Hi @mdalihusain This is because you are using firebase_messaging and phone auth at the same time (which both use notifications). The solution here is exactly what is mentioned in the error you are getting.

If you previously added the FirebaseAppDelegateProxyEnabled key with a false value to your Info.plist to disable swizzling; you can now remove it, the plugin now supports multiple delegates and will internally forward to any other plugins that may have previously registered a delegate.

You need to set up method swizzling to allow for multiple delegates (see https://github.com/FirebaseExtended/flutterfire/issues/1102). Does this solve the issue for you? Thank you

The problem is that this issue you mentioned is very old (about an year) and it was fixed in subsequent upgrades to flutter packages by flutter fire team as mentioned by @Salakar in the last comment of the issue you mentioned. And, thus I was able to use firebase auth and firebase messaging together without any issues. But as soon as I migrated to firebase_core: 0.7.0 , this issue has started to occur again..

mdalihusain avatar Feb 08 '21 19:02 mdalihusain

When you say you migrated to the new core version that also means you had to upgrade all of your other flutterfire packages, right?

I'm assuming the issue came when you updated messaging and auth to the latest as well.

Still the solution here is to do what the error message says, if you have disabled method swizzling you need to either enable it (deleting the FirebaseAppDelegateProxyEnabled in Info.plist should be enough) or you need to follow a guide for how to set up phone auth without method swizzling like https://firebase.google.com/docs/auth/ios/phone-auth#appendix:-using-phone-sign-in-without-swizzling

markusaksli-nc avatar Feb 09 '21 10:02 markusaksli-nc

Yes, I updated messaging and auth as well, but doesn't that mean that this issue can be solved by the flutter fire team rather than every developer making this change at their end because it was already solved in the previous versions of these packages.

Secondly, I have set FirebaseAppDelegateProxyEnabled to false in Info.plist as directed by the FlutterFire Documentation of FirebaseMessaging. So, wouldn't it cause any issue if I remove it from Info.plist?

Also, this guide you shared is for Swift/Objective-C iOS development not Flutter, so its really complicated how to use it for my project

mdalihusain avatar Feb 10 '21 05:02 mdalihusain

Do you mean this step in the outdated installation guide on pub.dev? (see the updated guide here)

If you need to disable the method swizzling done by the FCM iOS SDK (e.g. so that you can use this plugin with other notification plugins) then add the following to your application's Info.plist file.

This was an optional step if you needed to use multiple notification plugins. Unless you needed to disable it for some other notification plugin you are using then no, removing it shouldn't break anything. Removing that value or setting it to <true/> should fix the issue.

As for this being our responsibility to fix. Sadly this repository only wraps the upstream native Firebase SDKs and it's just a fact that the Firebase iOS SDK uses method swizzling for handling phone auth. As I said they have a native workaround if you need to disable method swizzling but as you mentioned it is complicated to implement. It is still possible but it's simpler to just allow method swizzling.

It might be that this worked with the previous version of firebase messaging had a deprecated FCM route for notifications but now they are all handled through APNs only. This isn't really something we can or should fix. The default use case here is just to not disable FirebaseAppDelegateProxyEnabled so it wouldn't make sense for us to implement a native workaround when by default the iOS SDK relies on method swizzling.

markusaksli-nc avatar Feb 10 '21 08:02 markusaksli-nc

Hey @mdalihusain. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot avatar Feb 19 '21 02:02 google-oss-bot

I'm experiencing the same, after updating to firebase_core: 0.7.0 and firebase_auth: 0.20.0+1 my implementation for phone verification stopped working with the same mentioned error:

If app delegate swizzling is disabled, remote notifications received by UIApplicationDelegate need to be forwarded to FIRAuth's canHandleNotificaton: method.

I never had the key FirebaseAppDelegateProxyEnabled on my Info.plist file. It's working fine on Android but I also noticed that now it's redirecting to another page to verify the client isn't a bot.

It might be something related to reCaptcha callback that's not working for iOS.

I'm not sure what else can I provide here to report this issue that should be considered high impact imo.

renannery avatar Mar 01 '21 08:03 renannery

Hey @mdalihusain. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot avatar Mar 10 '21 02:03 google-oss-bot

Since there haven't been any recent updates here, I am going to close this issue.

@mdalihusain if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

google-oss-bot avatar Mar 19 '21 01:03 google-oss-bot

Do you mean this step in the outdated installation guide on pub.dev? (see the updated guide here)

If you need to disable the method swizzling done by the FCM iOS SDK (e.g. so that you can use this plugin with other notification plugins) then add the following to your application's Info.plist file.

This was an optional step if you needed to use multiple notification plugins. Unless you needed to disable it for some other notification plugin you are using then no, removing it shouldn't break anything. Removing that value or setting it to <true/> should fix the issue.

As for this being our responsibility to fix. Sadly this repository only wraps the upstream native Firebase SDKs and it's just a fact that the Firebase iOS SDK uses method swizzling for handling phone auth. As I said they have a native workaround if you need to disable method swizzling but as you mentioned it is complicated to implement. It is still possible but it's simpler to just allow method swizzling.

It might be that this worked with the previous version of firebase messaging had a deprecated FCM route for notifications but now they are all handled through APNs only. This isn't really something we can or should fix. The default use case here is just to not disable FirebaseAppDelegateProxyEnabled so it wouldn't make sense for us to implement a native workaround when by default the iOS SDK relies on method swizzling.

I set the FirebaseAppDelegateProxyEnabled key to <true/> in Info.plist file. But still getting the same error - [firebase_auth/notification-not-forwarded] If app delegate swizzling is disabled, remote notifications received by UIApplicationDelegate need to be forwarded to FIRAuth's canHandleNotificaton: method.

mdalihusain avatar Mar 23 '21 13:03 mdalihusain

Since there haven't been any recent updates here, I am going to close this issue.

@mdalihusain if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

Please open this issue

mdalihusain avatar Mar 24 '21 05:03 mdalihusain

Does the issue persist on the latest versions of the packages and if you just remove FirebaseAppDelegateProxyEnabled from Info.plist entirely?

markusaksli-nc avatar Mar 24 '21 14:03 markusaksli-nc

Does the issue persist on the latest versions of the packages and if you just remove FirebaseAppDelegateProxyEnabled from Info.plist entirely?

Yes, the issue still persists, after upgrading to all the latest packages and removing FirebaseAppDelegateProxyEnabled from Info.plist

mdalihusain avatar Mar 26 '21 14:03 mdalihusain

I'm also getting the same behavior in my code. I upgraded to all the latest Firebase packakges, I do not have the FirebaseAppDelegateProxyEnabled flag in my Info.plist file, and when trying to authenticated with phone I get the error:

(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.)

amitkot avatar Apr 13 '21 10:04 amitkot

Although the migration guide states that:

If you manually import Firebase and configure it via [FIRApp configure]; or FirebaseApp.configure() within your projects ios/{projectName}/AppDelegate{.m/.swift} file, you can now safely remove it - FlutterFire automatically handles this for you.

I kept getting this error when calling the phone auth method:

If app delegate swizzling is disabled, remote notifications received by UIApplicationDelegate need to be forwarded to FIRAuth's canHandleNotificaton: method.

What fixed the authentication issue for me was:

  1. Setting the FirebaseAppDelegateProxyEnabled flag to boolean NO
  2. Changing AppDelegate.swift to:
import UIKit
import Flutter
import Firebase
import FirebaseAuth
import UserNotifications
import FirebaseInstanceID

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
  ) -> Bool {
        FirebaseApp.configure()
        GeneratedPluginRegistrant.register(with: self)
        return true
  }
    override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        let firebaseAuth = Auth.auth()
        firebaseAuth.setAPNSToken(deviceToken, type: AuthAPNSTokenType.unknown)

    }
    override func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        let firebaseAuth = Auth.auth()
        if (firebaseAuth.canHandleNotification(userInfo)){
            print(userInfo)
            return
        }
    }
}

(based on https://github.com/FirebaseExtended/flutterfire/issues/1102#issuecomment-581202025)

amitkot avatar Apr 13 '21 14:04 amitkot

@markusaksli-nc does the new version of Firebase for Flutter require the above AppDelegate implementation for using Auth and Messaging at the same time?

If so, this part of the migration document is incorrect:

If you manually import Firebase and configure it via [FIRApp configure]; or FirebaseApp.configure() within your projects ios/{projectName}/AppDelegate{.m/.swift} file, you can now safely remove it - FlutterFire automatically handles this for you.

amitkot avatar Apr 19 '21 14:04 amitkot

I'm experiencing the same error as @amitkot. Also had to do the same fixes to manually forward APNS token and notification payload.

Snippet from our pubspec:

  firebase_core: ^1.0.2
  cloud_firestore: ^1.0.2
  cloud_functions: ^1.0.2
  firebase_analytics: ^8.0.1
  firebase_dynamic_links: ^2.0.1
  firebase_auth: ^1.0.1
  firebase_crashlytics: ^2.0.0
  firebase_messaging: ^9.0.1
  firebase_storage: ^8.0.0

MrAlek avatar Apr 20 '21 10:04 MrAlek

Echoing the same findings as @MrAlek. Experienced the same problems as @amitkot after migrating our project to Flutter 2 and updating dependencies—thankfully, @amitkot's workarounds did the trick. Never had FirebaseAppDelegateProxyEnabled defined in Info.plist before.

Here's a snippet from our pubspec:

  firebase_core: ^1.2.0
  firebase_auth: ^1.2.0
  firebase_storage: ^8.1.0
  firebase_messaging: ^9.1.4
  firebase_crashlytics: ^2.0.4
  firebase_remote_config: ^0.10.0-dev.3

senmu avatar May 18 '21 20:05 senmu

For those who are interested in a working solution for the latest versions of firebase libraries:

import UIKit
import Flutter
import Firebase
import FirebaseAuth
import UserNotifications
import FirebaseMessaging

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
    override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        let firebaseAuth = Auth.auth()
        firebaseAuth.setAPNSToken(deviceToken, type: AuthAPNSTokenType.unknown)

    }
    override func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        let firebaseAuth = Auth.auth()
        if (firebaseAuth.canHandleNotification(userInfo)){
            print(userInfo)
            return
        }
    }
}

al-muammar avatar Aug 08 '21 18:08 al-muammar

A few more comments here.

  1. When I upgraded to the latest core, messaging & authentication versions, suddenly push notifications stopped to work both on ios & android
  2. The snippet I put above in fact breaks push notifications on ios (but phone auth still works). Here is the corrected snippet that works for me:
import UIKit
import Flutter
import FirebaseAuth

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
  override func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
      let firebaseAuth = Auth.auth()
      if (firebaseAuth.canHandleNotification(userInfo)){
          print(userInfo)
          return
      }
  }
}

al-muammar avatar Aug 21 '21 19:08 al-muammar