0

Trying to save logged in parse user's value, it only works for the first time but when i close the app and reopen it, it doesn't work again.

This is the save code I'm using which seems alright

PFUser.current()["about"] = textfield.text
PFUser.current().saveInBackground()

and this is the error i get when trying to save the objects to current user.

PFKeychainStore failed to set object for key 'currentUser', with error: -34018 
or
cannot modify user objectIDxx

This started happening after i installed parse server instead of parse.com

1 Answer 1

1

Were you using "revocable sessions" before? If not, parse-server requires you to use them. You can check out the migration tutorial here.

You'll need to add this after you initialize parse:

[PFUser enableRevocableSessionInBackground]

And then you will need to re-login a user if you get an 'invalid session' error from parse.

// Swift
class ParseErrorHandlingController {
  class func handleParseError(error: NSError) {
    if error.domain != PFParseErrorDomain {
      return
    }

    switch (error.code) {
    case kPFErrorInvalidSessionToken:
      handleInvalidSessionTokenError()

    ... // Other Parse API Errors that you want to explicitly handle.
  }

  private class func handleInvalidSessionTokenError() {
    //--------------------------------------
    // Option 1: Show a message asking the user to log out and log back in.
    //--------------------------------------
    // If the user needs to finish what they were doing, they have the opportunity to do so.
    //
    // let alertView = UIAlertView(
    //   title: "Invalid Session",
    //   message: "Session is no longer valid, please log out and log in again.",
    //   delegate: nil,
    //   cancelButtonTitle: "Not Now",
    //   otherButtonTitles: "OK"
    // )
    // alertView.show()

    //--------------------------------------
    // Option #2: Show login screen so user can re-authenticate.
    //--------------------------------------
    // You may want this if the logout button is inaccessible in the UI.
    //
    // let presentingViewController = UIApplication.sharedApplication().keyWindow?.rootViewController
    // let logInViewController = PFLogInViewController()
    // presentingViewController?.presentViewController(logInViewController, animated: true, completion: nil)
  }
}

// In all API requests, call the global error handler, e.g.
let query = PFQuery(className: "Object")
query.findObjectsInBackgroundWithBlock { (objects: [AnyObject]!, error: NSError!) -> Void in
  if error == nil {
    // Query Succeeded - continue your app logic here.
  } else {
    // Query Failed - handle an error.
    ParseErrorHandlingController.handleParseError(error)
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

yes i tried this, still happening, deleted my app, made new account. not sure what's exactly wrong.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.