我有兴趣根据currentUser执行的操作将属性保存到数据库中的用户.基于以下代码,我收到错误消息“除非已通过logIn或signUp验证用户,否则无法保存用户”
NSString *IDToFetch = @"some_id"; PFQuery *query = [PFUser query]; [query whereKey:@"user_id" equalTo:IDToFetch]; PFUser *foundUser = (PFUser *)[query getFirstObject]; foundUser[@"new_column"] = @"Some text"; [foundUser saveEventually]; //here an exception is thrown
解决方法
如果要更新当前不是登录用户的用户,则需要使用主密钥调用Parse.
您可以从CloudCode执行此操作;
Parse.Cloud.define('editUser',function(request,response) { var userId = request.params.userId,newColText = request.params.newColText; var User = Parse.Object.extend('_User'),user = new User({ objectId: userId }); user.set('new_col',newColText); Parse.Cloud.useMasterKey(); user.save().then(function(user) { response.success(user); },function(error) { response.error(error) }); });
并从您的iOS项目中调用它;
[PFCloud callFunction:@"editUser" withParameters:@{ @"userId": @"someuseridhere",@"newColText": @"new text!" }];