目前正在开发一个以 parse.com 作为后端的登录系统。我已经输入了我认为完全有效的代码,但我仍然得到无效的登录参数。
我不知道发生了什么......
import UIKit
import Parse
class ViewController: UIViewController {
@IBOutlet weak var userEmailAddressTextField:UITextField!
@IBOutlet weak var userPasswordTextField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func signInButtonTapped(sender: AnyObject) {
let userEmail = userEmailAddressTextField.text
let userPassword = userPasswordTextField.text
if(userEmail.isEmpty || userPassword.isEmpty) {
return
}
PFUser.logInWithUsernameInBackground(userEmail, password: userPassword) {
(user:PFUser?, error:NSError?) -> Void in
var userMessage = "Welcome!"
if(user != nil)
{
} else {
userMessage = error!.localizedDescription
}
var myAlert = UIAlertController(title: "Alert", message: userMessage, preferredStyle: UIAlertControllerStyle.Alert)
let okAction = UIAlertAction(title: "ok", style: UIAlertActionStyle.Default, handler: nil)
myAlert.addAction(okAction)
self.presentViewController(myAlert, animated: true, completion: nil)
}
}
最佳答案
@IBAction func signInButtonTapped(sender: AnyObject) {
let userEmail = userEmailAddressTextField.text
let userPassword = userPasswordTextField.text
if userEmail.isEmpty || userPassword.isEmpty {
println("You forgot to fill in some fields, please try again.")
}
PFUser.logInWithUsernameInBackground(userEmail, password: userPassword) {
(user: PFUser?, error: NSError?) -> Void in
if user != nil {
// Do stuff after successful login.
} else {
var myAlert = UIAlertController(title: "Alert", message: userMessage, preferredStyle: UIAlertControllerStyle.Alert)
let okAction = UIAlertAction(title: "ok", style: UIAlertActionStyle.Default, handler: nil)
myAlert.addAction(okAction)
self.presentViewController(myAlert, animated: true, completion: nil)
}
}
我相信这段代码应该可以解决您的问题。如果这不起作用,请确保在 AppDelegate.swift 中正确输入您的客户端 key 和应用程序 ID。
关于ios - parse.com 中的登录参数无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32274129/