gpt4 book ai didi

swift - 无法修改用户解析

转载 作者:行者123 更新时间:2023-11-28 16:01:55 25 4
gpt4 key购买 nike

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

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

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

最佳答案

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

您需要在初始化解析后添加:

[PFUser enableRevocableSessionInBackground]

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

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

关于swift - 无法修改用户解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40906313/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com