无法修改用户Parse

时间:2016-12-01 08:59:57

标签: swift parse-platform parse-server

尝试保存已登录的解析用户的值,它只在第一次有效,但是当我关闭应用并重新打开它时,它不再起作用。

这是我正在使用的保存代码,似乎没问题

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

这是我在尝试将对象保存到当前用户时遇到的错误。

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

这是在我安装解析服务器而不是parse.com

之后开始的

1 个答案:

答案 0 :(得分:1)

您以前使用过“可撤销会话”吗?如果没有,parse-server要求您使用它们。您可以查看迁移教程here

初始化解析后,您需要添加此内容:

[PFUser enableRevocableSessionInBackground]

如果您从解析中收到“无效会话”错误,则需要重新登录用户。

// 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)
  }
}