我的if
语句无法运行。我不知道为什么它不会运行。
@IBOutlet weak var Email: UITextField!
@IBOutlet weak var Password: UITextField!
@IBAction func Login(_ sender: AnyObject) {
let email = Email.text
let password = Password.text
let postURL = URL(string: "https://www.example.com/app/signin.php?email" + email! + "&password" + password!)!
var postRequest = URLRequest(url: postURL)
postRequest.httpMethod = "POST"
postRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
postRequest.setValue("application/json", forHTTPHeaderField: "Accept")
let httpBODY = postRequest.httpBody
let mail : Data = email!.data(using: .utf8)!
if httpBODY == mail { // Error is happening right here
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "LoggedOn")
self.navigationController?.pushViewController(vc, animated: true)
} else {
let title = "Wrong!"
let message = "Incorrect username or bad Password."
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
let OKAction = UIAlertAction(title: "OK", style: .default)
alertController.addAction(OKAction)
var alertWindow : UIWindow!
alertWindow = UIWindow.init(frame: UIScreen.main.bounds)
alertWindow.rootViewController = UIViewController.init()
alertWindow.windowLevel = UIWindowLevelAlert + 1
alertWindow.makeKeyAndVisible()
alertWindow.rootViewController?.present(alertController, animated: true)
}
}
预期:该按钮将获取电子邮件和密码,并向url发送请求。如果电子邮件和密码有效,它将显示该电子邮件。如果电子邮件等于HTTP正文,则它将重定向到LoggedOn故事板。
发生了什么:该按钮将获取电子邮件和密码,并向url发送请求。如果电子邮件和密码有效,它将显示该电子邮件。如果电子邮件等于HTTP正文,则不执行任何操作。
情节提要板未连接到LoggedOn情节提要板上。我不知道是否需要。有人可以帮我弄清楚发生了什么事吗?