0

I'm using Xcode to build my first iPhone app. Basically, I want to track my GPS location and based on that, get data from a web service. Then I want to display that data. Actually, I want to have a robot speak the data, but one issue at a time.

I found this thread:

https://stackoverflow.com/a/1791658/400732

which points to a great example from Apple, that shows how to track the location. So, how do I now call out to the web service? The less Objective-C, the better, because I'm really a Python, Javascript programmer.

Community
  • 1
  • 1
egilchri
  • 761
  • 1
  • 5
  • 19

1 Answers1

1

To post data and recive responses use ASIFormDataRequest

NSURL *url = [NSURL URLWithString:@"http://yourwebsite.com"];

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:@"x_coordinate" forKey:@"x"];
[request setPostValue:@"y_coordinate" forKey:@"y"];

[request startSynchronous];

NSError *error = [request error];
if (!error && [request responseStatusCode] == 200) {
      NSLog(@"This is the response from the server: %@",[request responseString]];
}else{
      NSLog(@"Error - Data download error: \"%@\"",[[request error] localizedDescription]);
}
Cyprian
  • 9,423
  • 4
  • 39
  • 73
  • Thanks. I'm exploring the idea that biting the bullet, and learning how to write native apps,is a better way for me that wrestling with PhoneGap. – egilchri Dec 18 '11 at 18:53
  • I was reading somewhere that ASIFormDataRequest isn't being supported, going forward. So I decided not to use it. I found this tutorial had just the sort of code I needed to see. http://www.raywenderlich.com/5492/working-with-json-in-ios-5 – egilchri Jan 20 '12 at 21:11