Reputation: 437
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
Upvotes: 0
Views: 567
Reputation: 2188
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)
}
}
Upvotes: 1