Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase电子邮件身份验证iOS:“;这封电子邮件的格式不正确;_Ios_Swift_Email_Firebase_Firebase Authentication - Fatal编程技术网

Firebase电子邮件身份验证iOS:“;这封电子邮件的格式不正确;

Firebase电子邮件身份验证iOS:“;这封电子邮件的格式不正确;,ios,swift,email,firebase,firebase-authentication,Ios,Swift,Email,Firebase,Firebase Authentication,尝试创建Firebase登录/注册,但无论我在电子邮件文本字段中输入什么,它都会打印错误“电子邮件地址格式不正确”,即使是有效的电子邮件。而且我是初学者,所以…对格式很抱歉。代码如下: import UIKit import Firebase import FirebaseAuth class SecondViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad

尝试创建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!)
        }

    }
}
)}
}
}
)
}
}

我的代码供参考看看

//Outlets
        @IBOutlet weak var emailTextField: UITextField!
        @IBOutlet weak var passwordTextField: UITextField!

    //Sign Up Action for email
    @IBAction func createAccountAction(_ sender: AnyObject) {

        let email = emailTextField.text
        let pass = passwordTextField.text
        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 {
            Auth.auth().createUser(withEmail: email!, password: pass!) { (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)
                }
            }



        }
    }

为我工作我使用了我的代码而不是你的尝试设置断点并检查崩溃实际发生的位置