gpt4 book ai didi

ios - Parse.com - 保存新 PFObject 时出现错误 101

转载 作者:行者123 更新时间:2023-11-28 22:23:55 24 4
gpt4 key购买 nike

我正在创建一个新的 PFObject,在其上设置一些对象,然后像这样保存它:

// Add a new 'madeTitle' Activity Object
PFObject* madeTitleActivity = [PFObject objectWithClassName:kPAPActivityClassKey];
[madeTitleActivity setObject:aComment forKey:kWSActivityCommentKey];
[madeTitleActivity setObject:self.photo forKey:kPAPActivityPhotoKey];
[madeTitleActivity setObject:[PFUser currentUser] forKey:kPAPActivityFromUserKey];
[madeTitleActivity setObject:[aComment objectForKey:kWSCommentsFromUserKey] forKey:kPAPActivityToUserKey];
[madeTitleActivity setObject:kPAPActivityTypeMadeTitle forKey:kPAPActivityTypeKey];

// ACL's
PFACL *ACL = [PFACL ACLWithUser:[PFUser currentUser]];
[ACL setPublicReadAccess:YES];
[ACL setWriteAccess:YES forUser:[PFUser currentUser]];
madeTitleActivity.ACL = ACL;


[madeTitleActivity saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {

if (succeeded) {
// ...
}
else {
NSLog(@"madeTitleActivity saveInBackgroundWithBlock -- error = %@", error);
}
}];

但我收到以下错误:

2013-10-22 10:55:12.546 WSPhoto[2064:7b4b] Error: object not found for update (Code: 101, Version: 1.2.6)
2013-10-22 10:55:12.552 WSPhoto[2064:707] madeTitleActivity saveInBackgroundWithBlock -- error = Error Domain=Parse Code=101 "The operation couldn’t be completed. (Parse error 101.)" UserInfo=0x8966c0 {code=101, error=object not found for update}

我之前处理过这个错误,但它一直与更新对象和 ACL 问题有关。创建和保存新对象时,我没有出现此错误代码。

我检查了我设置的所有对象,它们都返回有效对象。

我还成功地保存了一些其他 Activity 对象,据我所知代码看起来完全一样。


编辑:扩展代码,包括嵌套 madeTitleActivity 代码的 CloudCode 函数调用

 [PFCloud callFunctionInBackground:@"setCommentIsTitle"
withParameters:@{@"userID":[[PFUser currentUser] objectId],
@"objectId":[aComment objectId],
@"photoObjectId":[self.photo objectId],
@"previousCommentObjectId":[previousTitleComment objectId],
@"isTitle":[NSNumber numberWithBool:YES],
@"previousCommentObjectIsTitle":[NSNumber numberWithBool:NO]}
block:^(NSMutableDictionary *results , NSError *error) {

if (!error) {
// Add a new 'madeTitle' Activity Object
PFObject* madeTitleActivity = [PFObject objectWithClassName:kPAPActivityClassKey];
[madeTitleActivity setObject:aComment forKey:kWSActivityCommentKey];
[madeTitleActivity setObject:self.photo forKey:kPAPActivityPhotoKey];
[madeTitleActivity setObject:[PFUser currentUser] forKey:kPAPActivityFromUserKey];
[madeTitleActivity setObject:[aComment objectForKey:kWSCommentsFromUserKey] forKey:kPAPActivityToUserKey];
[madeTitleActivity setObject:kPAPActivityTypeMadeTitle forKey:kPAPActivityTypeKey];

// ACL's
PFACL *madeTitleACL = [PFACL ACLWithUser:[PFUser currentUser]];
[madeTitleACL setPublicReadAccess:YES];
[madeTitleACL setWriteAccess:YES forUser:[PFUser currentUser]];
madeTitleActivity.ACL = madeTitleACL;

[madeTitleActivity saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {

NSLog(@"madeTitleActivity saveInBackgroundWithBlock -- called");

if (succeeded) {
// ..
}
else {
NSLog(@"madeTitleActivity saveInBackgroundWithBlock -- error = %@", error);
}
}];
}

else {
NSLog(@"etCommentIsTitle PFCloud -- error = %@", error);
}
}];

最佳答案

这个:

Error: object not found for update

表示您正在尝试保存一个与尚未保存的其他对象有关系的对象。你不能那样做,因为它不存在。

您需要找出它的另一个对象并确保首先保存它。


请注意,您可以使用其中一种 saveAll... 方法批量保存多个新对象,既可以避免此类问题,又可以提高效率。

关于ios - Parse.com - 保存新 PFObject 时出现错误 101,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19525602/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com