我在iOS上使用Swift。
我的应用有一个帖子列表。您可以匿名阅读,但必须注册才能发布。
当您打开应用程序时,您将获得一个匿名帐户。我在AppDelegate中添加了以下内容
PFUser.enableAutomaticUser()
PFUser.currentUser()?.incrementKey("RunCount")
PFUser.currentUser()?.saveInBackground()
我从以下代码获得了代码:https://www.parse.com/docs/ios/guide#users-anonymous-users
当你去发帖时我已经注册了
let user = PFUser.currentUser()
user?.username = displayNameTextField.text
user?.password = passwordTextField.text
user?.email = emailTextField.text
user!.signUpInBackgroundWithBlock { ... }
这成功了。我可以在服务器上看到用户正在更新。但是我收到209错误:[错误]:会话令牌无效(代码:209,版本:1.7.4)
我已经尝试过查看sessiontoken并在每一步都将其打印出来并保持不变。我听说当用户注销时sessiontokens无效,但我以为我只是签了用户而不是用户。为什么sessiontoken无效?
我尝试使用sessiontoken将用户设置为PFUser.Become()的当前用户,但这也不起作用。
我显然忽略了一些东西,但我无法弄清楚是什么。任何帮助都非常感激。
答案 0 :(得分:12)
同样的问题开始发生在我身上,我意识到这是因为在应用设置中启用了此选项:
Revoke existing session tokens when user changes password - YES/NO
我怀疑这是在匿名用户上设置密码的意外副作用 - 我不认为在这种情况下会话令牌需要重置的原因。
希望这将得到修复,但解决方法是在signUp方法成功后立即调用logInWithUsername方法。
答案 1 :(得分:0)
您没有正确执行登录,请尝试此操作
func login() {
var user = PFUser()
user.username = "myUsername"
user.password = "myPassword"
user.signUpInBackgroundWithBlock {
(succeeded: Bool, error: NSError?) -> Void in
if let error = error {
let errorString = error.userInfo?["error"] as? NSString
// Show the errorString somewhere and let the user try again.
} else {
// Hooray! Let them use the app now.
}
}
}
代码let user = PFUser.currentUser()
仅显示当前登录的用户。
在创建任何请求之前,您还必须使用Parse进行身份验证,最好的位置是appDelegate
函数内didFinishLaunchingWithOptions
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
Parse.setApplicationId("Your Id go Here", clientKey: "Your clientKey go here")
return true
}
ID和clientKey的值在Parse中可用,并且对于您的accont
是唯一的我希望能帮到你,祝你好运!