How to use FirebaseUI for Google authentication on iOS in Swift?

后端 未结 3 1189
误落风尘
误落风尘 2021-01-20 19:51

I\'m following https://firebase.google.com/docs/auth/ and want to use FirebaseUI (https://github.com/firebase/FirebaseUI-iOS/tree/master/FirebaseUI) for authentication.

3条回答
  •  被撕碎了的回忆
    2021-01-20 20:36

    Is your AppDelegate a FIRAuthUIDelegate?

    Anyway, instead of using delegates, you can make use of FIRAuth listener: func addAuthStateDidChangeListener(listener: FIRAuthStateDidChangeListenerBlock) -> FIRAuthStateDidChangeListenerHandle

    You can use it this way:

    FIRAuth.auth()?.addAuthStateDidChangeListener {
    
        (auth, user) in
    
        if user != nil {
    
            print("user signed in")
    
        }
    
    }
    

    You can see a working sample on https://github.com/cooliopas/FirebaseAuth-Demo

    Its in spanish, but I'm sure you will understand the code.

提交回复
热议问题