【问题标题】:Cannot modify user Parse无法修改用户解析
【发布时间】:2016-12-01 08:59:57
【问题描述】:

试图保存登录的解析用户的值,它只在第一次工作,但是当我关闭应用程序并重新打开它时,它不再工作了。

这是我正在使用的保存代码,看起来不错

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 后开始发生

【问题讨论】:

    标签: swift parse-platform parse-server


    【解决方案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)
      }
    }
    

    【讨论】:

    • 是的,我试过了,仍然发生,删除了我的应用程序,创建了新帐户。不知道到底出了什么问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-05
    • 1970-01-01
    • 2018-03-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多