我有一个有 2 个 View Controller 的应用程序。一个是登录/注册页面,另一个是应该更改 UILabel 以显示用户电子邮件的页面,但事实并非如此。我想这是因为我没有来自第一个 View Controller 的数据。那么如何从第一个 View Controller 获取数据呢?
这是来自 SecondViewController.swift
的部分代码
if let user = FIRAuth.auth()?.currentUser {
self.usernameLabel.text = user.email
print(user.email)
}
最佳答案
您想要从 Firebase DB 获取用户电子邮件的单个事件“快照”。该电子邮件作为字典条目存储在 Firebase 中。所以这对我有用:
let uid = FIRAuth.auth()?.currentUser?.uid
FirDatabase.database().reference()child("YOUR_FIREBASE_CHILD_NODE").child(uid!).
observeSingleEvent(of: .value, with: { (snapshot) in
if let dictionary = snapshot.value as? [String:Any] {
self.usernameLabel.text = dictionary["email"] as? String
}
关于ios - 如何在 iOS 应用中共享 Firebase 身份验证数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43106829/