2014-09-27 67 views
0

我试图更新我用Parse保存的聊天对象,虽然它有时会起作用,但并不一致。如果我清除对象了在浏览器端的数据,它会奏效了几次,但后来我得到的错误:解析更新对象错误:找不到更新的对象(代码:101,版本:1.3.0)

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]; 

    }]; 

良好的措施,这是解析推荐:

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

我用来解决这个问题的代码是让对象(本例中为聊天室)的每个用户拥有ACL权限,以便在首次创建PFObject时编辑(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,所以我不认为这是一种重复。

+0

这不是人们想要的授权。 – 2015-02-19 18:13:38