ios - How to access response.body from a JavaScript function called in Objective-C? -


i'm using parse cloud code handle server-side logic ios app.

i query parse chatrooms objects. if desired object exists, have no problem accessing it, if have create external javascript function (to around user permission issues), having trouble accessing object returned said js function.

ios viewcontroller.

-(void)chatroomquery {    ....      [combinedchatroomquery findobjectsinbackgroundwithblock:^(nsarray *objects, nserror *error) {         if (![objects count] == 0) {             [self.chatbutton settitle:@"continue chat user" forstate:uicontrolstatenormal];             self.selectedchat = objects[0];         }         else if ([objects count] == 0){             [self.chatbutton settitle:@"create new chat user" forstate:uicontrolstatenormal];             [pfcloud callfunctioninbackground:@"adduserstochatroom" withparameters:@{@"user1" : [pfuser currentuser].objectid, @"user2" : self.giveitem.itemgiver.objectid} block:^(id object, nserror *error) {                 self.selectedchat = response.body.currentchat;             }];         };     }];  } 

the "else if" block calls javascript function saved parse cloud code:

parse.cloud.define("adduserstochatroom", function(request, response){    parse.cloud.usemasterkey();     var user1id = request.params.user1;   var user2id = request.params.user2;    var user = parse.object.extend("user");   var user1 = new user({ objectid: user1id });   var user2 = new user({ objectid: user2id });    var chatroom = parse.object.extend("chatroom");   var currentchat = new chatroom();    currentchat.set("user1", user1);   currentchat.set("user2", user2);    currentchat.save(null, {     success: function(currentchat){         console.log("yeaaa chat room saved");         response.body = currentchat;     },     error: function(currentchat, error){         console.log("failed save chatroom" + error.message);     }   });  }); 

as can see in ios code sample, under else if block, set

self.selectedchat = response.body.currentchat; 

but error

use of undeclared identifier "response" 

how access response.body of javascript function?

your cloud code should return success method instead of setting body property:

response.success(currentchat); 

your ios code should accessing returned object, not body of response doesn't exist:

self.selectedchat = object; 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -