0

I have implemented Firebase Auth (sign in with Apple) and Firebase firestore in an app live on the App Store. I implemented a listener for authentication state in the scene delegate from the firebase documentation. https://firebase.google.com/docs/auth/ios/start

It checks if the user is logged in or not. The code aims to present a login view controller if there is no user registered or the main view controller if the user already created an account & hasn't logout at the start up.

However, I had feedback from users that after sign out & login, the app keep crashing both in live or in testFlight, I don't have anything reported in Crashlytics or App Store Connect. I am looking for help from people that encountered the same problems.

 var handle: AuthStateDidChangeListenerHandle?

 handle = Auth.auth().addStateDidChangeListener { (auth, user) in
        if((user) != nil){
            let home = TabBar()
            home.selectedIndex = 1
            self.window?.rootViewController = home
        } else if((user) == nil) {
            print("Not Logged in")
            let signup = SignUpVC()
            self.window?.rootViewController = signup
        }
    }
Sully07
  • 11
  • 2
  • We definitely need more info. Can you reproduce the bug with the debugger attached? Even in a Release build could be enough. – Tiziano Coroneo May 06 '20 at 19:43
  • I wasn't able to reproduce the bug, I only know that it is certainly due to a lack of memory on the device, that makes the OS kill the app ( the app is crashing, make the iPhone load & bring back to lock screen). This issue appears since I added the auth listener & implement this logic in my app. – Sully07 May 07 '20 at 19:22

1 Answers1

1

Resolved: The crash was causing by a memory leaks due to a strong reference cycle. here is a great tutorial to understand it: https://www.youtube.com/watch?v=q0-DIJszYRo In order to avoid that, I used weak & [weak self]

weak var handle: AuthStateDidChangeListenerHandle?

handle = Auth.auth().addStateDidChangeListener { [weak self] (auth, user) in

That's solve the problem, the OS is not killing the app anymore due to a lack of memory.

Sully07
  • 11
  • 2