2014-09-27 41 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