MAMP and the iOS Simulator


If you want to test an app that will work with a HTTP server, then one way to do this is with MAMP and the iOS Simulator. Here's a brief and simple example to get you started.

There's no special setup, just open MAMP, start the server as usual and run your app in the iOS Simulator.

iOS code

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://127.0.0.1:8888/hello.php?name=Harry"]];

NSError *error = nil;
NSURLResponse *response = nil;

NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

NSString* responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];

NSLog(@"%@",responseString);

}

PHP code (hello.php)

<?php

if(isset($_GET['name'])) echo "Hello ".$_GET['name'];

?>


Endorse on Coderwall

Comments