【发布时间】:2017-07-06 00:04:24
【问题描述】:
尝试创建 Firebase 登录/注册,但无论我在电子邮件文本字段中输入什么,它都会打印错误“电子邮件地址格式错误”,即使它是有效的电子邮件。另外我是初学者,所以......对格式感到抱歉。这是代码:
import UIKit
import Firebase
import FirebaseAuth
class SecondViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// FirebaseApp.configure()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBOutlet weak var username_input: UITextField!
@IBOutlet weak var password_input: UITextField!
@IBOutlet weak var signupButton: UIButton!
@IBOutlet weak var segmentControl: UISegmentedControl!
@IBAction func doSignUp(_ sender: Any) {
let email = self.username_input.text
let password = self.password_input.text
if email != "" && password != ""
{
if segmentControl.selectedSegmentIndex == 1 //signup
{
Auth.auth().createUser(withEmail: email!, password: password!, completion: { (user, error) in
if error == nil {
print("You have successfully signed up")
// Goes to main page
let vc = self.storyboard?.instantiateViewController(withIdentifier: "Home")
self.present(vc!, animated: true, completion: nil)
self.performSegue(withIdentifier: "segue", sender: self)
let request = Auth.auth().currentUser?.createProfileChangeRequest()
request?.displayName = email
}
else {
if (error?.localizedDescription) != nil
{
// 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)
print(error?.localizedDescription as Any)
let myError1 = error?.localizedDescription
print(myError1!)
}
}
})
}
}
if segmentControl.selectedSegmentIndex == 0 {
//login
Auth.auth().signIn(withEmail: self.username_input.text!, password: self.password_input.text!, completion: { (user, error) in
if user != nil
{
self.performSegue(withIdentifier: "segue", sender: self)
//sign in user
}
else
{
if (error?.localizedDescription) != nil
{
_ = UIAlertController(title: "Error", message: error?.localizedDescription, preferredStyle: .alert)
let myError = error?.localizedDescription
print(myError!)
}
else {
Auth.auth().signIn(withEmail: self.username_input.text!, password: self.password_input.text!, completion: { (user, error) in
if user != nil
{
self.performSegue(withIdentifier: "segue", sender: self)
//sign in user
}
else
{
if (error?.localizedDescription) != nil
{
_ = UIAlertController(title: "Error", message: error?.localizedDescription, preferredStyle: .alert)
let myError = error?.localizedDescription
print(myError!)
}
}
}
)}
}
}
)
}
}
【问题讨论】:
-
为我工作我使用我的代码而不是你的代码尝试设置断点并检查崩溃实际发生的位置
标签: ios swift email firebase firebase-authentication