Search code examples
iosobjective-cruby-on-railsjsonrestkit

how to send json from iOS device to rails server


I always used parse.com for this sorts of things and get rid of the backend pain but as a developer i wanted to upgrade myself and dived into the rails pool.

right now, i successfully created everything with these methods

NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonMutableDictionary
                                                   options:NSJSONWritingPrettyPrinted // Pass 0 if you don't care about the readability of the generated string
                                                     error:&error];
NSLog(@" json data form %@",jsonData);

NSString* newStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];

NSLog(@"Json string form");

and this is the json that i want to send

  {
  "id" : 27,
  "login_screen" : 1,
  "last_name_button_clicked" : 0,
  "last_name" : "herose",
  "set_first_name_button_clicked" : 0,
  "first_name" : "george"
}

now i'v been looking through all over the places but couldn't find a right way to do this in asynchronous way to not harm the user experience.

and i got absolutely no idea on how to get these key-value pairs in my rails server,

do i create a route in my routes file with GET method?

how will it work?

Any kind of information is useful :)

Cheers


Solution

  • I imagine you'd use NSURLSession to send JSON to a server.

    Here's a good NSURLSession tutorial.

    Hope it helps!