【发布时间】:2021-09-05 08:42:40
【问题描述】:
所以我在我的 ios 应用程序中使用 firebase 身份验证,我想在视图控制器上的 UIlabels 中显示电子邮件地址和用户名。但是当我在 UIlabel 上显示 Auth.auth().email 的值时,标签会显示 Optional"email adress"。我如何摆脱 Optional 以及如何允许用户在 firebase 身份验证中拥有显示名称?
import Firebase
import FirebaseAuth
class ProfileViewController: UIViewController {
@IBOutlet weak var profiepic: UIImageView!
@IBOutlet weak var UsernameLabel: UILabel!
@IBOutlet weak var EmailLabel: UILabel!
@IBOutlet weak var league: UILabel!
@IBOutlet weak var Achievements: UIButton!
@IBOutlet weak var resetpasswd: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
UsernameLabel.layer.borderColor = UIColor.black.cgColor
EmailLabel.layer.borderColor = UIColor.black.cgColor
league.layer.borderColor = UIColor.black.cgColor
Achievements.layer.cornerRadius = 55/2
resetpasswd.layer.cornerRadius = 55/2
resetpasswd.layer.borderColor = UIColor.black.cgColor
displayinfo()
}
func displayinfo() {
let user = Auth.auth().currentUser
if let user = user {
// The user's ID, unique to the Firebase project.
// Do NOT use this value to authenticate with your backend server,
// if you have one. Use getTokenWithCompletion:completion: instead.
let email = user.email
let photoURL = user.photoURL
EmailLabel.text = "Email: \(email)"
// ...
}
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
}
【问题讨论】:
-
您可以在此线程中找到解决方案 [stackoverflow.com/questions/35944483/…