我一直在努力解決這個問題幾天,我是一名菜鳥,我無法找到解決方案。我正嘗試使用XCode 8.3.3創建用戶註冊和登錄頁面,並將Firebase用作數據庫。無法使用Firebase身份驗證:FIRAuth.auth不起作用
我的代碼如下:
import UIKit
import Firebase
import FirebaseAuth
class SignUpViewController: UIViewController {
//Outlets
@IBOutlet weak var emailTextField: UITextField!
@IBOutlet weak var passwordTextField: UITextField!
//Sign Up Action for email
@IBAction func createAccountAction(_ sender: AnyObject) {
if emailTextField.text == "" {
let alertController = UIAlertController(title: "Error", message: "Please enter your email and password", preferredStyle: .alert)
let defaultAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
alertController.addAction(defaultAction)
present(alertController, animated: true, completion: nil)
} else {
FIRAuth.auth().createUser(withEmail: emailTextField.text!, password: passwordTextField.text!) { (user, error) in
if error == nil {
print("You have successfully signed up")
//Goes to the Setup page which lets the user take a photo for their profile picture and also chose a username
let vc = self.storyboard?.instantiateViewController(withIdentifier: "Home")
self.present(vc!, animated: true, completion: nil)
} else {
let alertController = UIAlertController(title: "Error", message: error?.localizedDescription, preferredStyle: .alert)
let defaultAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
alertController.addAction(defaultAction)
self.present(alertController, animated: true, completion: nil)
}
}
}
}
有問題的部分是FIRAuth.auth
。該錯誤表示「FIRAuth
已重命名爲Auth」,如果我應用了此類修復程序,雖然構建成功,但我只能看到白色屏幕。如果我刪除了代碼,則可以看到之前創建的正常登錄屏幕。
另一件事是當我輸入FirebaseAuth
一個紅線出現在建議的單詞列表中劃掉FirebaseAuth
,我仍然繼續。
請幫忙。我不知道爲什麼會發生。會不會有任何缺少的pod文件?非常感激。
故事板: storyboard
您是否在AppDelegate中配置Firebase? – PGDev
嘗試移除導入的FirebaseAuth。 – PGDev
將您的窗格更新爲Firebase SDK 4.0 –