flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

🐛 [firebase_auth] verifyPhoneNumber error - If app delegate swizzling is disabled, remote notifications received by UIApplicationDelegate need to be forwarded to FIRAuth's canHandleNotificaton: method.

Open Justus-M opened this issue 2 years ago • 16 comments

Bug report

Describe the bug

when I try to use FirebaseAuth.instance.verifyPhoneNumber, verificationFailed triggers with the following message: "If app delegate swizzling is disabled, remote notifications received by UIApplicationDelegate need to be forwarded to FIRAuth's canHandleNotificaton: method."

According to some other issues I read, this is because I'm also using firebase messaging.

This should be fixed according to https://github.com/firebase/flutterfire/issues/4970#issuecomment-1024108801

Steps to reproduce

Steps to reproduce the behavior:

run FirebaseAuth.instance.verifyPhoneNumber with your phone number

I have the latest versions of firebase_messaging, firebase_core, and firebase_authentication

Expected behavior

I expect to receive an sms verification code

Justus-M avatar Jun 30 '22 19:06 Justus-M

I'm getting the same error after adding firebase_messaging to my project. Already tried multiple solutions found on old issues and threads, nothing works. Also tried using older firebase_messaging version alongside the latest firebase_auth version, no success.

ArielFarias avatar Jun 30 '22 23:06 ArielFarias

I'm getting the same error after adding firebase_messaging to my project. Already tried multiple solutions found on old issues and threads, nothing works. Also tried using older firebase_messaging version alongside the latest firebase_auth version, no success.

After half a day, I got it running by replacing my entire AppDelegate.swift file with the following


import UIKit
import Flutter
import Firebase

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    FirebaseApp.configure()
    GeneratedPluginRegistrant.register(with: self)
    if #available(iOS 10.0, *) {
      UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
    }
    if(!UserDefaults.standard.bool(forKey: "Notification")) {
        UNUserNotificationCenter.current().removeAllPendingNotificationRequests()
        UserDefaults.standard.set(true, forKey: "Notification")
    }
      
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
    
    override func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        super.application(application, didReceiveRemoteNotification: userInfo, fetchCompletionHandler: completionHandler)
          let firebaseAuth = Auth.auth()
            Messaging.messaging().appDidReceiveMessage(userInfo)
            print(userInfo)
          if (firebaseAuth.canHandleNotification(userInfo)){
              completionHandler(.noData)
              return
          }
      }

}


I still think this shouldn't be necessary though, especially given that it hasn't been necessary with certain versions in the past, and using both fcm and sms verification together is very common.

Justus-M avatar Jul 01 '22 00:07 Justus-M

Thank you for sharing your solution, it is my second day trying to figure this out. Unfortunately your solution does not work for me. I'm using firebase_auth: 3.3.20 and firebase_messaging: 10.2.6. Did you added this to your Info.plist?

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

I tried with and without using the same AppDelegate as you suggested. Still received the error message while trying to validate a phone number.

ArielFarias avatar Jul 01 '22 03:07 ArielFarias

@Justus-M and @ArielFarias This is because silent push notifications are needed for phone auth. Firebase messaging without app delegate swizzling will consume all of the messages and it will not work. In order to use firebase messaging with anything else that needs to receive the message data natively you need to enable it. See https://firebase.google.com/docs/auth/ios/phone-auth#appendix:-using-phone-sign-in-without-swizzling for more reference and check if it helps.

darshankawar avatar Jul 01 '22 09:07 darshankawar

@darshankawar Is it normal to expect flutter developers with no native iOS/swift experience to go in and modify swift code? As far as I can recall, this is pretty much the only time it's necessary

This documentation seems to be created for iOS developers, not flutter developers.

According to several comments in other threads, this was not an issue with some past versions of the packages, so it seems to be preventable.

Using push notifications and phone verification together is very common, and I think it should not be necessary for a flutter developer to go through documentation created for iOS developers to make that work.

I realize I should just familiarize myself with swift more to become a better developer, but I stand by my point, because the point of flutter and flutterfire is partially not to have to deal with stuff like this, especially for such a typical use case

Justus-M avatar Jul 01 '22 09:07 Justus-M

@Justus-M Thanks for feedback. Flutterfire plugins are wrappers around native Firebase sdks and leverages implementation by sending and receiving data through Dart and the ios documentation seems to be an example of it. Have you tried already to make changes as mentioned in the document and confirm if it works ?

darshankawar avatar Jul 01 '22 09:07 darshankawar

@darshankawar The link you provided leads to some code snippets which I guess should be implemented. 2 things are unclear to me as a flutter developer with no native knowledge (this is the difference between iOS/swift developer docs and flutter developer docs)

  1. Where should these changes be made? I don't even know which file to look at
  2. Which of these snippets need to be implemented? Do I just copy and paste all of them in?

Justus-M avatar Jul 01 '22 10:07 Justus-M

@Justus-M and @ArielFarias This is because silent push notifications are needed for phone auth. Firebase messaging without app delegate swizzling will consume all of the messages and it will not work. In order to use firebase messaging with anything else that needs to receive the message data natively you need to enable it. See https://firebase.google.com/docs/auth/ios/phone-auth#appendix:-using-phone-sign-in-without-swizzling for more reference and check if it helps.

I tried to understand what to do with these snippets, (but as a Flutter developer I don't have knowlege with native iOS, only native Android). Anyway I put them inside of AppDelegate.swift and got the same error on phone verification.

What does not makes sense is why we need to do this now if that was not needed in older versions of firebase_auth and firebase_messaging. The company where I work have an app published on both, iOS and Google store for more than a year now which uses firebase_messaging and firebase_auth with phone authentication and works fine, none of these native swift code are implemented there.

ArielFarias avatar Jul 01 '22 13:07 ArielFarias

Thanks for the update and feedback. I am keeping this open and labeling it for further insights from the team.

/cc @russellwheatley. For your reference: similar issue and resolution comment: https://github.com/firebase/flutterfire/issues/4970#issuecomment-1024108801 . Also, https://github.com/firebase/flutterfire/issues/9010#issuecomment-1172135199

darshankawar avatar Jul 04 '22 10:07 darshankawar

Hi, the same issue is happening to me as well on the latest versions of firebase_messaging and firebase_auth. Replacing AppDelegate.swift works as well, but the app crashes on first install. (I don't know how to fix it since I'm not a native developer) Further investigations would be appreciated.

MinseokKang003 avatar Jul 19 '22 07:07 MinseokKang003

After days of trying, I found out that phone authentication and messaging both works properly without replacing AppDelegate.swift and without disabling method swizzling on previous versions below.

firebase_core: ^1.17.0 firebase_auth: ^3.3.18 firebase_messaging: ^11.4.0

There might have been some regression on recent version upgrades.

MinseokKang003 avatar Jul 19 '22 18:07 MinseokKang003

After days of trying, I found out that phone authentication and messaging both works properly without replacing AppDelegate.swift and without disabling method swizzling on previous versions below.

firebase_core: ^1.17.0 firebase_auth: ^3.3.18 firebase_messaging: ^11.4.0

There might have been some regression on recent version upgrades.

Strangely, this isn't working for me. I restored my old AppDelegate.swift file and switched to your recommended package versions, but received the error again.

Unfortunately replacing AppDelegate.swift results in an app crash for some of my users during firebase auth sms verification, so I'm still looking for a workaround that doesn't involve replacing AppDelegate.swift, But I currently don't have any other solutions.

Justus-M avatar Jul 30 '22 20:07 Justus-M

That's weird. As soon as I upgrade firebase dependencies, phone authentication stops working again. What is your AppDelegate.swift?

MinseokKang003 avatar Jul 31 '22 08:07 MinseokKang003

That's weird. As soon as I upgrade firebase dependencies, phone authentication stops working again. What is your AppDelegate.swift?

Thanks for your quick response.

When I tried your recommended packages I changed my AppDelegate.swift back to this:

import UIKit
import Flutter

@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)
  }

Justus-M avatar Jul 31 '22 09:07 Justus-M

Hi, the same issue is happening to me as well on the latest versions of firebase_messaging and firebase_auth. Replacing AppDelegate.swift works as well, but the app crashes on first install. (I don't know how to fix it since I'm not a native developer) Further investigations would be appreciated.

Im having the exactly same issue. For some ios users, the app crashes on the First phone auth try. Does any1 have an updated solution?

danielcmm avatar Sep 20 '22 01:09 danielcmm

After trying & searching for a half day I found its simple solution 😂 Just import Firebase. Make sure you don't import any other Firebase libraries. As I was using Maps too, So I'm going to share my own AppDelegate.swift file

import UIKit
import Flutter
import GoogleMaps
import Firebase

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    FirebaseApp.configure()
    GMSServices.provideAPIKey("*************************")
    GeneratedPluginRegistrant.register(with: self)
    if #available(iOS 10.0, *) {
      UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
    }
    if(!UserDefaults.standard.bool(forKey: "Notification")) {
        UNUserNotificationCenter.current().removeAllPendingNotificationRequests()
        UserDefaults.standard.set(true, forKey: "Notification")
    }

    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }

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

}

No need to import FirebaseAuth, FirebaseMessaging or FirebaseAnalytics in your AppDelegate.swift.

MicroProgramer avatar Sep 20 '22 02:09 MicroProgramer

After days of trying, I found out that phone authentication and messaging both works properly without replacing AppDelegate.swift and without disabling method swizzling on previous versions below.

firebase_core: ^1.17.0 firebase_auth: ^3.3.18 firebase_messaging: ^11.4.0

There might have been some regression on recent version upgrades.

@MinseokKang003 old packages are no longer working with other newer packages. were you able to fix this issue?

@Justus-M Any update on a solution?

sachindarde avatar Sep 23 '22 21:09 sachindarde

I am facing this issue as well. For the first time ios users, the app is crashing.

My AppDelegate code :

import UIKit
import Flutter
import Firebase

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    FirebaseApp.configure()
    GeneratedPluginRegistrant.register(with: self)
    if #available(iOS 10.0, *) {
      UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
    }
    if(!UserDefaults.standard.bool(forKey: "Notification")) {
        UNUserNotificationCenter.current().removeAllPendingNotificationRequests()
        UserDefaults.standard.set(true, forKey: "Notification")
    }

    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }

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

Using the following pubs : firebase_auth: ^3.11.0 firebase_messaging: ^13.0.4

Also FirebaseAppDelegateProxyEnabled is set to Boolean NO as suggested on google's firebase description.

Any update on a solution for this ?

credwise14 avatar Sep 30 '22 16:09 credwise14

After days of trying, I found out that phone authentication and messaging both works properly without replacing AppDelegate.swift and without disabling method swizzling on previous versions below. firebase_core: ^1.17.0 firebase_auth: ^3.3.18 firebase_messaging: ^11.4.0 There might have been some regression on recent version upgrades.

@MinseokKang003 old packages are no longer working with other newer packages. were you able to fix this issue?

@Justus-M Any update on a solution?

Check here: https://github.com/firebase/flutterfire/issues/9010?notification_referrer_id=NT_kwDOBFmOV7MzOTE0MTUzOTg3OjcyOTc4MDA3&notifications_query=is%3Aunread#issuecomment-1251750689

MicroProgramer avatar Oct 06 '22 01:10 MicroProgramer

I am facing this issue as well. For the first time ios users, the app is crashing.

My AppDelegate code :

import UIKit
import Flutter
import Firebase

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    FirebaseApp.configure()
    GeneratedPluginRegistrant.register(with: self)
    if #available(iOS 10.0, *) {
      UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
    }
    if(!UserDefaults.standard.bool(forKey: "Notification")) {
        UNUserNotificationCenter.current().removeAllPendingNotificationRequests()
        UserDefaults.standard.set(true, forKey: "Notification")
    }

    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }

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

Using the following pubs : firebase_auth: ^3.11.0 firebase_messaging: ^13.0.4

Also FirebaseAppDelegateProxyEnabled is set to Boolean NO as suggested on google's firebase description.

Any update on a solution for this ?

C

I am facing this issue as well. For the first time ios users, the app is crashing.

My AppDelegate code :

import UIKit
import Flutter
import Firebase

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    FirebaseApp.configure()
    GeneratedPluginRegistrant.register(with: self)
    if #available(iOS 10.0, *) {
      UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
    }
    if(!UserDefaults.standard.bool(forKey: "Notification")) {
        UNUserNotificationCenter.current().removeAllPendingNotificationRequests()
        UserDefaults.standard.set(true, forKey: "Notification")
    }

    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }

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

Using the following pubs : firebase_auth: ^3.11.0 firebase_messaging: ^13.0.4

Also FirebaseAppDelegateProxyEnabled is set to Boolean NO as suggested on google's firebase description.

Any update on a solution for this ?

Check here: https://github.com/firebase/flutterfire/issues/9010?notification_referrer_id=NT_kwDOBFmOV7MzOTE0MTUzOTg3OjcyOTc4MDA3&notifications_query=is%3Aunread#issuecomment-1251750689

MicroProgramer avatar Oct 06 '22 01:10 MicroProgramer

Did anyone come up with a good solution to this? My app was working perfectly until recently and too many things have changed since I went back and tried my login screen. It could be updating to flutter 3.7.0 or one of my recently added libraries. the updates to AppDelegate did fix the problem on my end but I worry that it will cause crashes as mentioned by others.

jasonJamEther avatar Feb 02 '23 02:02 jasonJamEther

@jasonJamEther For me the solution in the end was using static versions of all my firebase libs, which is not recommended, but if it works it works.

      firebase_core: 1.20.0
      firebase_auth: 3.5.0
      firebase_messaging: 12.0.1
      firebase_storage: 10.3.3
      cloud_firestore: 3.4.1
      firebase_dynamic_links: 4.2.5
      firebase_analytics: 9.1.0
      firebase_crashlytics: 2.0.4
      firebase_performance: 0.8.0+13
      firebase_remote_config: 2.0.1
      firebase_in_app_messaging: 0.6.0+8
  
  dependency_overrides:
      firebase_auth_platform_interface: 6.4.0
      firebase_core_platform_interface: 4.5.1

That is my current AppDelegate file:

import Flutter
import Firebase

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

    // That is for logging out from firebase auth after doing logout in Flutter code
    let userDefaults = UserDefaults.standard
    if userDefaults.value(forKey: "appFirstTimeOpend") == nil {
        //if app is first time opened then it will be nil
        userDefaults.setValue(true, forKey: "appFirstTimeOpend")
        // signOut from Auth
        do {
            try Auth.auth().signOut()
        } catch {

        }
    }

  return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}

Also note that I'm not changing or setting any FirebaseAppDelegateProxyEnabled key!

ArielFarias avatar Feb 02 '23 13:02 ArielFarias

@jasonJamEther Benim için çözüm, tüm firebase lib'lerimin statik sürümlerini kullanmaktı, bu önerilmez, ancak çalışırsa çalışır.

      firebase_core: 1.20.0
      firebase_auth: 3.5.0
      firebase_messaging: 12.0.1
      firebase_storage: 10.3.3
      cloud_firestore: 3.4.1
      firebase_dynamic_links: 4.2.5
      firebase_analytics: 9.1.0
      firebase_crashlytics: 2.0.4
      firebase_performance: 0.8.0+13
      firebase_remote_config: 2.0.1
      firebase_in_app_messaging: 0.6.0+8
  
  dependency_overrides:
      firebase_auth_platform_interface: 6.4.0
      firebase_core_platform_interface: 4.5.1

Bu benim mevcut AppDelegate dosyam:

import Flutter
import Firebase

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

    // That is for logging out from firebase auth after doing logout in Flutter code
    let userDefaults = UserDefaults.standard
    if userDefaults.value(forKey: "appFirstTimeOpend") == nil {
        //if app is first time opened then it will be nil
        userDefaults.setValue(true, forKey: "appFirstTimeOpend")
        // signOut from Auth
        do {
            try Auth.auth().signOut()
        } catch {

        }
    }

  return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}

Ayrıca herhangi bir FirebaseAppDelegateProxyEnabled anahtarını değiştirmediğimi veya ayarlamadığımı unutmayın !****

Thank you for the answer. Have you ever experienced crashes with this AppDelegate file?

Cengizhanerturan avatar Feb 02 '23 14:02 Cengizhanerturan

Thank you for the answer. Have you ever experienced crashes with this AppDelegate file?

No.

ArielFarias avatar Feb 02 '23 14:02 ArielFarias

Thank you for the answer. Have you ever experienced crashes with this AppDelegate file?

No.

Thank you for your quick reply. I see that your AppDelegate is not importing UIKit, what's the reason?

Cengizhanerturan avatar Feb 02 '23 14:02 Cengizhanerturan

import Flutter
import Firebase

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

    // That is for logging out from firebase auth after doing logout in Flutter code
    let userDefaults = UserDefaults.standard
    if userDefaults.value(forKey: "appFirstTimeOpend") == nil {
        //if app is first time opened then it will be nil
        userDefaults.setValue(true, forKey: "appFirstTimeOpend")
        // signOut from Auth
        do {
            try Auth.auth().signOut()
        } catch {

        }
    }

  return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}

@ArielFarias I get an error when I use this AppDelegate code you shared. The error I got: "If app delegate swizzling is disabled, remote notifications received by UIApplicationDelegate need to be forwarded to FIRAuth's canHandleNotificaton: method."

Cengizhanerturan avatar Feb 02 '23 15:02 Cengizhanerturan

Thank you for the answer. Have you ever experienced crashes with this AppDelegate file?

No.

Thank you for your quick reply. I see that your AppDelegate is not importing UIKit, what's the reason?

Because I dont need? I barely know swift, I work with Flutter for mobile development and just do things on swift when it is needed, therefore I have no idea what the UIKit lib does or why it is not needed.

ArielFarias avatar Feb 02 '23 15:02 ArielFarias

Thank you for the answer. Have you ever experienced crashes with this AppDelegate file?

No.

Thank you for your quick reply. I see that your AppDelegate is not importing UIKit, what's the reason?

Because I dont need? I barely know swift, I work with Flutter for mobile development and just do things on swift when it is needed, therefore I have no idea what the UIKit lib does or why it is not needed.

import Flutter
import Firebase

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

    // That is for logging out from firebase auth after doing logout in Flutter code
    let userDefaults = UserDefaults.standard
    if userDefaults.value(forKey: "appFirstTimeOpend") == nil {
        //if app is first time opened then it will be nil
        userDefaults.setValue(true, forKey: "appFirstTimeOpend")
        // signOut from Auth
        do {
            try Auth.auth().signOut()
        } catch {

        }
    }

  return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}

@ArielFarias I tried with the AppDelegate file you sent but it doesn't work. How did it work for you?

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

Cengizhanerturan avatar Feb 03 '23 08:02 Cengizhanerturan

I remember that in my case, other third-party dependencies which use APNs was the culprit. It was RevenueCat or Stream Chat or Onesignal or something. As I completely removed it, it started working again(Check for pubspec.lock and native pods if it is completely removed). I didn't have to do any special stuff.

MinseokKang003 avatar Feb 03 '23 10:02 MinseokKang003

I remember that in my case, other third-party dependencies which use APNs was the culprit. It was RevenueCat or Stream Chat or Onesignal or something. As I completely removed it, it started working again(Check for pubspec.lock and native pods if it is completely removed). I didn't have to do any special stuff.

I have firebase_messaging and I have to use that. In this case, can't we use it together with firebase_messaging?

Cengizhanerturan avatar Feb 03 '23 11:02 Cengizhanerturan