2015-08-28 60 views
0

當前正在以parse.com作爲後端的登錄系統上工作。我輸入了我認爲完全有效的代碼,但仍然收到無效的登錄參數。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) 
     } 
    } 

回答

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) 

    } 
} 

我相信這個代碼應該是解決你的問題。如果這不起作用,請確保您的客戶端密鑰和應用程序ID在AppDelegate.swift中正確輸入。

+0

如果這對您有用,請接受此爲正確答案,以便用戶在將來可以看到相同的答案。 –

+0

感謝您的答案......但它似乎並沒有工作......它仍然是無效的登錄參數,它顯示的消息是我放在其他語句後的消息。所以這意味着它是零。 – NewBeginnings

+0

nvmd它的工作感謝您的幫助! – NewBeginnings