解析更新对象错误:找不到更新的对象(代码:101,版本:1.3.0)

时间:2014-09-27 03:14:39

标签: ios objective-c xcode parse-platform pfobject

我正在尝试更新我用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];

}];

“守则”有时会运作,所以我知道这不是问题。我只是不确定是什么。

1 个答案:

答案 0 :(得分:-1)

我用来解决这个问题的代码是允许对象的每个用户(在这种情况下是聊天室)在首次创建时允许编辑(writeAccess)PFObject的ACL权限。为此,我使用了代码:

         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,所以我不认为它是重复的。