简体   繁体   中英

Error when calling PFCloud function from iOS app

I am using Cloud Code in order to add two users to a chatRoom, but my app crashes when I call the Cloud Code function.

In my iOS viewController , a user clicks a button which calls the following method:

-(void)createChatRoom
{
    PFQuery *queryForChatRoom = [PFQuery queryWithClassName:@"ChatRoom"];
    [queryForChatRoom whereKey:@"user1" equalTo:[PFUser currentUser]];
    [queryForChatRoom whereKey:@"user2" equalTo:self.giveItem.itemGiver];

    PFQuery *queryForChatRoomInverse = [PFQuery queryWithClassName:@"ChatRoom"];
    [queryForChatRoomInverse whereKey:@"user1" equalTo:self.giveItem.itemGiver];
    [queryForChatRoomInverse whereKey:@"user2" equalTo:[PFUser currentUser]];

    PFQuery *combinedChatRoomQuery = [PFQuery orQueryWithSubqueries:@[queryForChatRoom, queryForChatRoomInverse]];

    [combinedChatRoomQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if ([objects count] == 0){
            [PFCloud callFunctionInBackground:@"addUsersToChatRoom" withParameters:@{@"user1" : [PFUser currentUser]} block:^(id object, NSError *error) {
                [self performSegueWithIdentifier:@"itemToChatSegue" sender:nil];
            }];

        };
    }];

}

And here is the JavaScript function stored in my Parse Cloud .

Parse.Cloud.define("addUsersToChatRoom", function(request, response){
  response.success("Jared this method call works, no implement it");
  console.log("this is being logged to the console");
  var user = response.body.user1;
  console.log(user);
});

When I press the button to call this method, my app crashes and I get an output of errors that looks like this:

[PFInternalUtils encodeObject:allowUnsaved:allowObjects:]
[PFInternalUtils encodeObject:allowUnsaved:allowObjects:]
[PFCloud callFUnctionAsync:withParameters:]
[PFCloud callFunctionInBackground:withParameters:block:]
__36-[MyViewController createChatRoom]_block_invoke
__40-[PFTask thenCallBackOnMainThreadAsync:]_block_invoke_2

How can I move forward from this error?

Once the error is resolved, where will I be able to read the Cloud Code output? When I use curl to hit my app's Cloud Code ( https://parse.com/docs/cloud_code_guide ), I get the given "Hello world!" output, but in this case I'm calling the JS function from my objective-c code and I'm not sure where I can monitor my console output. (Ultimately, I will replace the console output that is currently in my JS function with the actual functionality I am looking for.)

How can I learn to make sense of this error-message output?

PFUser currentUser answers an object, but you must pass a dictionary of serializable types -- like the user id or username -- to callFunctionInBackground:withParameters: . Also, the cloud function should invoke either response.success() or response.error() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM