无法使用Firebase身份验证:FIRAuth.auth不起作用
我一直在努力解决这个问题几天,我是一名菜鸟,我无法找到解决方案。我正尝试使用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
FIRAuth
去年Firebase
版本成了Auth
。 link to Docs
import Firebase
然后,在application:didFinishLaunchingWithOptions:
方法,初始化FirebaseApp
对象:
// Use Firebase library to configure APIs
FirebaseApp.configure()
现在你可以在你的文件中使用(也import Firebase
)
Auth.auth().createUser(withEmail: email, password: password) { (user, error) in
// ...
}
希望它可以帮助
我试过了,并建成成功。但我得到了一个白色的屏幕,不是我的初始注册屏幕 –
@AndrewQin你有没有rootviewcontroller? –
@AndrewQin在函数func应用程序检查导航流量 –
您是否在AppDelegate中配置Firebase? – PGDev
尝试移除导入的FirebaseAuth。 – PGDev
将您的窗格更新为Firebase SDK 4.0 –