阅读背景:

如何在viewDidLoad()函数上正确读取Firebase数据库?

来源:互联网 
//Just a struct to save information about the User
var user = AppUser()

override func viewDidLoad() {
    super.viewDidLoad()

 //Verify if user is logged in
    verifyUser()
    user.email = "blabla"

    print("viewdidload user: \(user)")

}

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(true)

    print("viewdidappear user: \(user)")

} 

func verifyUser() {

    print("verify user called")

    //Log in verification
    guard let userID = Auth.auth().currentUser?.uid else {
        perform(#selector(handleLogOut), with: nil, afterDelay: 0)

        print("nil user")

        return
    }

    ref.child("users").child(userID).observeSingleEvent(of: .value, with: { (snapshot) in
        if let dictionary = snapshot.value as? [String: AnyObject] {
            self.user = AppUser(dictionary: dictionary)

            print(self.user)
        }
    }) { (error) in
        print(error.localizedDescription)
    }
}
//Just a struct to save information about the U



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: