ios - 如何在 iOS 应用中共享 Firebase 身份验证数据?

标签 ios swift firebase authentication firebase-authentication

我有一个有 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/

相关文章:

c# - 使用密码锁定 iPhone 设备

ios - 如何将 UIScrollView 'main' 内容设置为屏幕高度 - 'secondary' 内容 'below the fold'

ios - segue 创建 View Controller 的新实例 swift

ios - 在实体异常中找不到 keypath objectID

ios - 如何让SFSafariViewController在新窗口打开链接(IOS开发)

ios - 在 Objective-C 中使用通用的 Swift 类

iOS - 不工作 Sonar 脚本 'run-sonar-swift'

android - 当应用程序被杀死时,Android 中的长通知标题会被裁剪

android - 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态?

ios - Firebase putData 函数