ios - parse.com 中的登录参数无效

标签 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)
        }
    }

最佳答案

@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/

相关文章:

javascript - 如何在 Parse 中使用多个等于查询

ios - 第一个函数执行完成后如何调用第二个函数?

ios - 从 swift 应用程序的 OAuth 后台登录

ios - 在 Swift 2.2 中没有使用 Objective-C 选择器 'methodName()' 声明的方法

ios - iOS 中使用 parse.com 的帖子评分系统 - 赞成/反对

java - ParseQuery NullPointer 异常悖论

ios - 在 iOS 中使用 MPMediaItem 时,我需要使用 mutableCopy 到 NSMutableArray 吗?

swift - (关闭)Swift - UICollectionView 上下文菜单行

swift - FirebaseAuth 未通过 Google 身份验证创建新用户 - Swift

swift - 如何在 Swift 中处理异步请求?