0

我正在尝试更新我用 Parse 保存的聊天对象,虽然它有时有效,但并不一致。如果我在浏览器端从数据中清除对象,它将工作几次,但随后我收到错误消息:

Error: object not found for update (Code: 101, Version: 1.3.0)

这是我正在使用的代码,尽管我尝试了很多方法。此代码与 Parse 文档几乎相同。

PFObject *currentChatroom = _currentChatroom;
    NSString *objID = currentChatroom.objectId;
    PFQuery *query = [PFQuery queryWithClassName:@"Chats"];

    // Retrieve the object by id
    [query getObjectInBackgroundWithId:objID block:^(PFObject *fetchedChat, NSError *error) {

        // Now let's update it with some new data. In this case, only cheatMode and score
        // will get sent to the cloud. playerName hasn't changed.
        fetchedChat[@"lastTextSent"] = lastTextWithUser;
        fetchedChat[@"lastTextSentDate"] = date;
        [fetchedChat saveInBackground];

    }];

为了更好地衡量,这是 Parse 的建议:

PFQuery *query = [PFQuery queryWithClassName:@"GameScore"];

// Retrieve the object by id
[query getObjectInBackgroundWithId:@"xWMyZ4YEGZ" block:^(PFObject *gameScore, NSError *error) {

    // Now let's update it with some new data. In this case, only cheatMode and score
    // will get sent to the cloud. playerName hasn't changed.
    gameScore[@"cheatMode"] = @YES;
    gameScore[@"score"] = @1338;
    [gameScore saveInBackground];

}];

该代码有时会起作用,所以我知道这不是问题所在。我只是不确定是什么。

4

1 回答 1

-1

我用来解决这个问题的代码是允许对象的每个用户(在本例中为聊天室)在首次创建 PFObject 时拥有 ACL 权限来编辑(writeAccess)PFObject。为了做到这一点,我使用了以下代码:

         PFObject *newChatroom = [PFObject objectWithClassName:@"Chats"];

            // Create ACL to allow both users to edit/update the chatroom
         PFACL *multipleUserRights = [PFACL ACL];

            // _currentFriend is one user in the chatroom
         [multipleUserRights setReadAccess:YES forUser:_currentFriend];
         [multipleUserRights setWriteAccess:YES forUser:_currentFriend];

            // Give the current user permission as well 
         [multipleUserRights setReadAccess:YES forUser:[PFUser currentUser]];
         [multipleUserRights setWriteAccess:YES forUser:[PFUser currentUser]];

         newChatroom.ACL = multipleUserRights;

我发现了与此类似的问题,有些有类似的解决方案,但没有错误 1.3.0,所以我不会认为它是重复的。

于 2014-09-29T05:27:51.220 回答