我正在使用swift with xcode上解析我一直收到此错误:
[Error]: invalid login parameters (Code: 101, Version: 1.7.2)
每当我尝试登录用户时,我都知道用户是在解析后端中创建的,并且其信息是正确的。我该怎么做才能阻止此操作发生,并在没有应用程序发送无效登录参数的情况下登录?
这是我的LoginViewController:
import Foundation
import Parse
import UIKit
import Bolts
class LoginViewController: UIViewController, UITextFieldDelegate {
@IBOutlet weak var loginStatusLabel: UILabel!
@IBOutlet weak var emailTextField: UITextField!
@IBOutlet weak var passwordTextField: UITextField!
@IBOutlet weak var loginButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
emailTextField.delegate = self
passwordTextField.delegate = self
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func loginButtonPress(sender: AnyObject) {
login(emailTextField.text, password: passwordTextField.text)
}
func login(email: String, password: String)
{
PFUser.logInWithUsernameInBackground("email", password: "password")
{
(user: PFUser?, error: NSError?) -> Void in
if user != nil
{
user!.fetch()
if user!.objectForKey("emailVerified") as! Bool
{
self.loginStatusLabel.text = "Success!"
}
else if !(user!.objectForKey("emailVerified") as! Bool)
{
self.loginStatusLabel.text = "Verify your email address!"
}
else // status is "missing"
{
//TODO: Handle this error better
self.loginStatusLabel.text = "Verification status: Missing"
}
}
else
{
if let errorField = error!.userInfo
{
self.loginStatusLabel.text = (errorField["error"] as! NSString) as String
}
else
{
// No userInfo dictionary present
// Help from http://stackoverflow.com/questions/25381338/nsobject-anyobject-does-not-have-a-member-named-subscript-error-in-xcode
}
}
}
}
func textFieldShouldReturn(textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true;
}
}
我在登录用户时会出错吗?
您将字符串"email"
和"password"
传递给分析,而不是变量email
和password
的实际值。
将代码更改为:
PFUser.logInWithUsernameInBackground(email, password: password)
没有""