Simplifying NSURLConnections in iOS

April 5, 2013

Chances are, if you are creating an app in iOS, you will at some point be interacting with a connection to the server. All asynchronous requests need two components: the call, and when the connection receives data.

If you’re using an API, you will probably run into the need at some point to post to multiple URL’s having the same base and yet perhaps in multiple environments, one for testing and one for production.

If that is the case, you will need to set the base URL somewhere in your code. I chose this function:

- (void)applicationDidBecomeActive:(UIApplication *)application {
}

If you save your URL here as an NSUserdefault, you will be able to easily call up the URL wherever you need it. Then if you need to change your URL, you don’t have to update it in multiple places in your code.

Stay in Touch!

Subscribe to our newsletter.

Solutions Architecture

browse through our blog articles

Blog Archive