ios - 为非用户对象保存获取 "User cannot be saved unless they have been authenticated via logIn or signUp"

标签 ios swift parse-platform

这太奇怪了。昨晚开始出现,今天早上消失了,现在又出现了。我正在尝试将当前用户保存为关注者,将另一个用户保存为关注对象。代码是:

let follow = PFObject(className: "Follow")
follow["follower"] = PFUser.currentUser()
follow["following"] = ["__type": "Pointer", "className": "_User", "objectId": objectId]       
follow.saveInBackgroundWithBlock { (success, error) -> Void in
    if error != nil {
        print(error)
    }
}

错误是由我将当前用户设置为关注者的第二行引起的。如果我注释掉该行,那么 Follow 将保存在没有关注者的数据库中。但是对于这条线,它会抛出这个错误。

我不知道是什么原因造成的。任何帮助将不胜感激。

最佳答案

您是否在测试期间与其他用户一起登录?如果我通过登录/注销更改用户并且引用的对象是另一个具有脏 key 的用户(即需要保存的新数据),我就会看到此错误。

一个快速解决方法可能是尝试为当前用户创建一个指针,就像您为其他用户所做的那样:

let follow = PFObject(className: "Follow")
follow["follower"] = ["__type": "Pointer", "className": "_User", "objectId": PFUser.currentUser().objectId]       
follow["following"] = ["__type": "Pointer", "className": "_User", "objectId": objectId]       
follow.saveInBackgroundWithBlock { (success, error) -> Void in
    if error != nil {
        print(error)
    }
}

关于ios - 为非用户对象保存获取 "User cannot be saved unless they have been authenticated via logIn or signUp",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34746386/

相关文章:

ios - TableViewCell 中的 UIButton 调用 2 个函数

ios - 执行segue不工作

ios - ParseFacebookUtilsV4、Swift 和 CocoaPods : unresolved identifier

ios - 在 Swift 中执行后台保存

swift - 蛇在垂直方 block 中移动

Swift 选项错误

ios - HUD 在 iOS 中不工作

ios - 如何在 Storyboard 中将标签栏与其 View Controller 链接起来?

iphone - Objective-C——在 Cocoa-Touch 中处理触摸事件的选项

ios - "attempt to insert row 0 into section 0, but there are only 0 rows in section 0 after the update"尝试插入行时