今天是實作Firebase的功能:程式碼如下
import UIKit
import FirebaseAuth
import Firebase
class MemberShipViewController: BaseViewController {
@IBOutlet weak var btnLogin: CustomButton!
@IBOutlet weak var txfAccount: UITextField!
@IBOutlet weak var txfPassword: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
print("you enter MemberShipViewController!")
txfAccount.attributedPlaceholder = NSAttributedString(string: "Please Enter your Account....",attributes: [NSAttributedString.Key.foregroundColor: UIColor.orange])
txfPassword.attributedPlaceholder = NSAttributedString(string: "Please Enter your Password....",attributes: [NSAttributedString.Key.foregroundColor: UIColor.orange])
txfPassword.isSecureTextEntry = true
}
@IBAction func btnLoginTapped(_ sender: Any) {
Auth.auth().createUser(withEmail: txfAccount.text!, password: txfPassword.text!) { result, error in
guard let user = result?.user,
error == nil else {
print(error?.localizedDescription as Any)
return
}
print(user.email as Any, user.uid)
}
}
}