【发布时间】:2015-12-04 17:26:24
【问题描述】:
我正在尝试从 Parse 中另一个未经身份验证的 PFUser 更改另一个 PFUser 字段的值,但我似乎无法这样做。我正在尝试从另一个用户增加一个用户的“小时”数。以下是我尝试这样做的方式:
PFUser *currentUser = [PFUser currentUser];
PFACL *ACL = [PFACL ACLWithUser:[PFUser currentUser]];
[ACL setPublicReadAccess:YES];
PFUser *selectedUser = [self.formValues objectForKey:@"user"];
NSLog(@"User ID: %@", selectedUser.objectId);
PFObject *volunteerSheet = [PFObject objectWithClassName:@"VolunteerSheet"];
volunteerSheet[@"userID"] = selectedUser.objectId;
volunteerSheet[@"fromID"] = currentUser.objectId;
volunteerSheet[@"volunteerTitle"] = [self.formValues objectForKey:@"title"];
volunteerSheet[@"location"] = [self.formValues objectForKey:@"location"];
volunteerSheet[@"volunteerHours"] = [self.formValues objectForKey:@"hours"];
volunteerSheet[@"volunteerDescription"] = [self.formValues objectForKey:@"description"];
volunteerSheet.ACL = ACL;
[volunteerSheet saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (succeeded) {
// The object has been saved.
PFQuery *query = [PFQuery queryWithClassName:@"_User"];
// Retrieve the object by id
[query getObjectInBackgroundWithId:selectedUser.objectId
block:^(PFObject *user, NSError *error) {
[user incrementKey:@"volunteerHours" byAmount:(NSNumber*)[self.formValues objectForKey:@"hours"]];
[user saveInBackgroundWithBlock:^(BOOL succeeded, NSError * _Nullable error) {
if (succeeded) {
NSLog(@"Succeeded");
}else{
NSLog(error.description);
}
}];
}];
NSLog(@"Saved");
[self dismissViewControllerAnimated:YES completion:^{
UIAlertView * alert =[[UIAlertView alloc ] initWithTitle:@"Success!"
message:@"Hours Sent succesfully."
delegate:self
cancelButtonTitle:nil
otherButtonTitles: nil];
[alert addButtonWithTitle:@"Okay"];
[alert show];
}];
} else {
// There was a problem, check error.description
NSLog(@"Error: %@",error.description);
}
}];
【问题讨论】:
标签: ios objective-c iphone parse-platform pfuser