我已经在这个问题上挣扎了几天,我是一个菜鸟,我无法找到解决办法。我正在尝试使用XCode 8.3.3创建一个用户注册和登录页面,并使用Firebase作为数据库。
我的代码如下:
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”,如果我应用了这样的修复,尽管构建成功,但我只能看到一个白色屏幕。如果删除代码,则可以看到先前创建的正常登录屏幕。另一件事是,当我输入import
FirebaseAuth
时,建议的单词列表中出现了一条红线,划掉了FirebaseAuth
,我仍然继续。请帮忙。我不知道为什么会这样。有没有丢失的pod文件?非常感谢。
故事板:
storyboard
最佳答案
FIRAuth
在最后一个Auth
版本中变成了Firebase
。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
// ...
}
希望有帮助
关于ios - 无法使用Firebase身份验证:FIRAuth.auth不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44559027/