我正在使用xcode 8(swift 3)创建一些应用程序,我在创建Register类时遇到问题。您可能知道Firebase最近更新了,因此没有新版本的教程。我正在学习本教程,但没有成功:https://www.appcoda.com/firebase-login-signup/
import Foundation
import Firebase
import FirebaseAuth
import FirebaseAuthUI
import Toast_Swift
class Register: UIViewController{
@IBOutlet weak var emailField: UITextField!
@IBOutlet weak var passField: UITextField!
@IBAction func registerButton(_ sender: Any) {
let email = emailField.text
let pass = passField.text
if email != "" && pass != "" {
// Set Email and Password for the New User.
DataService.dataService.BASE_REF.createUser(email, password: password, withValueCompletionBlock: { error, result in
if error != nil {
// There was a problem.
self.signupErrorAlert("Ups!", message: "Nastao je problem pri kreiranju naloga. Probajte ponovo.")
} else {
// Create and Login the New User with authUser
DataService.dataService.BASE_REF.authUser(email, pass: pass, withCompletionBlock: {
err, authData in
let user = ["provider": authData.provider!, "email": email!]
// Seal the deal in DataService.swift.
DataService.dataService.createNewAccount(authData.uid, user: user)
})
// Store the uid for future access - handy!
NSUserDefaults.standardUserDefaults().setValue(result ["uid"], forKey: "uid")
// Enter the app.
self.performSegueWithIdentifier("NewUserLoggedIn", sender: nil)
}
})
} else {
signupErrorAlert("Ups!", message: "Zaboravili ste da popunite e-mail i/ili sifra polje.")
}
}
func signupErrorAlert(title: String, message: String) {
// Called upon signup error to let the user know signup didn't work.
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
let action = UIAlertAction(title: "Ok", style: .Default, handler: nil)
alert.addAction(action)
presentViewController(alert, animated: true, completion: nil)
}
}