无法从 PARSE Sdk 上的 iOS 更新对象

Not able to update object from iOS on PARSE Sdk

我已尝试从 Parse CloudCode 函数更新 Parse 对象。我想为 objectId 为 "vZveFx3KcP”. Whenever i call following function no entry gets updated. but whenever i added manual entry or entry from Android device it gets updated without any issue. For iOS i am using latest Parse version "1.11.0" 的一个特定条目更新 status_id。 我只遇到了由 iOS 平台添加的那些条目。

谁能解释一下我哪里出错了。我是 javascript 编程的新手,所以如果您需要我提供更多信息,请告诉我。您可以在下面查看我的代码。我尝试从 Parse API 控制台调用云函数。

   Parse.Cloud.define("freshFunction", function(request, response) {

               var GameScore = Parse.Object.extend("Booking");
               var query = new Parse.Query(GameScore);
               query.equalTo("objectId", "vZveFx3KcP");
               query.first({
                          success: function(results) {

                          alert("Successfully retrieved " + results.length + "user_id");

                          results.set("status_id", 2);
                          results.save();
                          response.success();
                          },
                          error: function(error) {
                          alert("Error: " + error.code + " " + error.message);
                           response.error();
                          }
                          });

               });

通过创建云函数并从 iOS 平台调用它解决了这个问题。在云中添加了以下代码。

Parse.Cloud.define("callCloudFunctionFromDevice", function(request, response) {

                   var bookfromtime = request.params.book_fromtime;
                   var booktotime = request.params.book_totime;
                   var bookdate = request.params.book_date;
                   var roommacid = request.params.room_mac_id;
                   var userid= request.params.user_id;
                   var ttl= request.params.title;
                   var desc= request.params.description;
                   var statusid= request.params.status_id;


                   var SensorsObject = Parse.Object.extend("Booking");
                   var senorObject = new SensorsObject();

                   senorObject.set("book_fromtime", bookfromtime);
                   senorObject.set("book_totime", booktotime);
                   senorObject.set("book_date", bookdate);
                   senorObject.set("room_mac_id", roommacid);
                   senorObject.set("user_id", userid);
                   senorObject.set("title", ttl);
                   senorObject.set("description", desc);
                   senorObject.set("status_id", statusid);




                   senorObject.save(null, {
                                    success: function(gameScore) {
                                    // response.success("Sensor Data is stored");
                                    response.success("success");
                                    },
                                    error: function(gameScore, error) {
                                    // Execute any logic that should take place if the save fails.
                                    // error is a Parse.Error with an error code and message.
                                    alert('Failed to create new object, with error code: ' + error.message);
                                    response.error("Failed to store object data");
                                    }
                                    });
                   });

在云上部署上述代码后,我从 iOS 平台调用了 'callCloudFunctionFromDevice' 函数。请参考以下代码

[PFCloud callFunctionInBackground:@"callCloudFunctionFromDevice" //This is the Parse function
                       withParameters:mDictionary
                                block:^(NSString *CalUsed1, NSError *error) { // This is where the block starts
                                    if (!error) { //if the block retrieves the data with no problem, this will run
                                        NSLog(@"Calories");
                                        [self hideBusyActivityView];
                                        [self.navigationController popViewControllerAnimated:YES];
                                    }
                                    else
                                    {
                                        NSLog(@"TDEE IN FN is");
                                        [self hideBusyActivityView];
                                        [self showAlertWithMessage:error.localizedDescription];
                                    }
                                }];

其中 mDictionary 是有效负载。

谢谢,

阿克谢阿赫尔。