parse.com中的登录参数无效

时间:2015-08-28 15:03:30

标签: ios swift parse-platform

目前正在使用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)
        }
    }

1 个答案:

答案 0 :(得分:0)

@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中正确输入了客户端密钥和应用程序ID。