不明白为什么我得到Parse 206错误(UserCannotBeAlteredWithoutSessionError)

时间:2015-03-20 14:56:26

标签: ios swift parse-platform cloud-code

PFCloud.callFunctionInBackground("updatePositions", withParameters: ["username" : username, "location" : locationTitle, "instructor" : instructorSwitch.on, "guard" : guardSwitch.on, "sup" : supSwitch.on]) {
    (positions: AnyObject!, error: NSError!) -> Void in
    if error == nil {

        self.currentUser.setValue(self.instructorSwitch.on, forKey: (self.shortTitle + "Instructor"))
        self.currentUser.setValue(self.guardSwitch.on, forKey: (self.shortTitle + "Guard"))
        self.currentUser.setValue(self.supSwitch.on, forKey: (self.shortTitle + "Sup"))

        self.currentUser.save(nil)

        self.navigationController?.popToRootViewControllerAnimated(true)
    }

    else {

        let errorAlert = UIAlertController (title: "Error", message: "There was an error while processing your request. This may be because the app could not connect to the internet. Please try again.", preferredStyle: UIAlertControllerStyle.Alert)

        let actionCancel = UIAlertAction (title: "Dismiss", style: .Cancel, handler: nil)

        errorAlert.addAction(actionCancel)

        self.presentViewController(errorAlert, animated: true, completion: nil)
    }

当我运行上面的代码时,我的目标是更新数据浏览器中的解析对象,同时在currentUser中编辑相同的对象。

现在,如果没有人登录,将显示Login VC(基于Core Data中的布尔值)。当用户登录时,他们将被带到应用主页(并且布尔值已更改)。如果他们要关闭应用程序并重新启动,它们将被带到主页而不是登录VC。我有一个"虚拟"核心数据实体更新的VC(我知道它听起来多余,但它的目的与我的问题无关)。

登录VC

@IBOutlet var fullName: UITextField!
@IBOutlet var password: UITextField!
@IBOutlet var helpButton: UIButton!
@IBOutlet var loginButton: UIButton!

var nameID: String!
var passwordStatus: Bool?
var username: String?
var userID: String?
var objectID: String!
var currentUser = PFUser.currentUser()

override func viewDidLoad() {
    super.viewDidLoad()

    navigationItem.hidesBackButton = true

    checkInternetConnection()
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

func textFieldShouldReturn(textField: UITextField) -> Bool {
    textField.resignFirstResponder()
    return true
}

override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
    self.view.endEditing(true)
}

@IBAction func LoginTapped(sender: AnyObject) {

    if (fullName.text.isEmpty || password.text.isEmpty) {

        let alert = UIAlertView()
        alert.title = "Error"
        alert.message = "You have not completed the required fields!"
        alert.addButtonWithTitle("Dismiss")
        alert.show()
    }

    else {

        PFUser.logInWithUsernameInBackground(fullName.text, password: password.text) {
            (user: PFUser!, error: NSError!) -> Void in

            if (user != nil) {

                self.currentUser = user

                self.currentUser.save()

                //println(self.currentUser.objectForKey("username") as String!)

                if (self.currentUser.objectForKey("passwordChanged")  as Bool! == nil || self.currentUser.objectForKey("passwordChanged") as Bool! == false) {

                    self.performSegueWithIdentifier("password", sender: self)
                }

                else {

                    self.performSegueWithIdentifier("skipPassword", sender: self)
                }
            }

            else {

                let errorAlert = UIAlertController (title: "Error", message: "Profile not found. Please check your username and password.", preferredStyle: UIAlertControllerStyle.Alert)

                let actionCancel = UIAlertAction (title: "Dismiss", style: .Cancel, handler: nil)

                errorAlert.addAction(actionCancel)

                self.presentViewController(errorAlert, animated: true, completion: nil)

            }
        }
    }
}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
    if (segue.identifier == "password") {
        var svc = segue.destinationViewController as AccountSetup

        svc.username = fullName.text

    }

    else if (segue.identifier == "skipPassword") {
        var svc = segue.destinationViewController as Agree

        svc.password = password.text
    }
}

用户有机会退出的唯一地方是应用程序的设置控制器:

设置VC

var choice: String!
var currentEmail: String!
var sendEmail: String!
var email: UITextField!
var listArray = NSArray (objects: "-", "-", "-", "1", "2", "3", "4", "5", "6")

var currentUser = PFUser.currentUser()

var res : NSManagedObject!
var context : NSManagedObjectContext!

override func viewDidLoad() {
    super.viewDidLoad()

    currentEmail = currentUser.objectForKey("email") as String!
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

// MARK: - Table view data source

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    // #warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 4
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // Return the number of rows in the section.

    switch(section) {
        case 0: return 2
        case 1: return 9
        case 2: return 4
        case 3: return 1
        default: fatalError("Unknown number of sections")
    }
}

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

    choice = listArray.objectAtIndex(indexPath.row) as NSString

    if (indexPath.row >= 3) {

        performSegueWithIdentifier("positions", sender: self)

    }

    else if (indexPath.row == 1) {

        var passwordAlert = UIAlertController (title: "Change Password", message: "For security reasons, you can not change your password through the app. We will send an email to " + currentEmail + ". If you rather us send it to another email, enter it below. Otherwise, click 'Send'.", preferredStyle: UIAlertControllerStyle.Alert)

        let standardCancel = UIAlertAction (title: "Dismiss", style: .Cancel, handler: nil)

        let actionSubmit = UIAlertAction (title: "Send", style: .Default) { (action) in

            if (self.email.text.isEmpty) {

                self.sendEmail = self.currentEmail
            }

            else {

                self.sendEmail = self.email.text
            }

            PFUser.requestPasswordResetForEmailInBackground(self.sendEmail){
                (success: Bool!, error: NSError!) -> Void in

                if (success == true) {

                    let emailAlert = UIAlertController (title: "Password", message: "An email containing information on how to change your password has been sent to " + self.sendEmail + ".", preferredStyle: UIAlertControllerStyle.Alert)

                    emailAlert.addAction(standardCancel)

                    self.presentViewController(emailAlert, animated: true, completion: nil)
                }

                else {

                    let errorAlert = UIAlertController (title: "Error", message: "There was an error while processing your request. This may be because the email is invalid or the app could not connect to the internet. Please try again.", preferredStyle: UIAlertControllerStyle.Alert)

                    errorAlert.addAction(standardCancel)

                    self.presentViewController(errorAlert, animated: true, completion: nil)
                }
            }
        }

        let actionCancel = UIAlertAction (title: "Cancel", style: .Cancel, handler: nil)

        passwordAlert.addTextFieldWithConfigurationHandler {

            (textField) in textField.placeholder = "Email"
            self.email = textField
        }

        passwordAlert.addAction(actionSubmit)
        passwordAlert.addAction(actionCancel)

        self.presentViewController(passwordAlert, animated: true, completion: nil)
    }
}


@IBAction func logoutPressed (sender: AnyObject) {

    PFUser.logOut()

    //code to change Core Data boolean value to start on Login is here but there is no need to put it (unrelated)

    tabBarController?.tabBar.hidden = true

    performSegueWithIdentifier("goToLogin", sender: self)

}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
    if (segue.identifier == "positions") {
        var svc = segue.destinationViewController as UpdatePositions;

        svc.locationTitle = choice
        println (choice)
    }
}

就像之前提到过的那样,一切正常,直到应用程序关闭,身份验证丢失。

1 个答案:

答案 0 :(得分:0)

结束1.6.0 Parse SDK中存在错误。适用于1.6.5。