Hi! Are you looking for a better way to talk to the internets in your iPhone, iPad and Mac applications? Before you answer: hi. (If you don’t get this, please listen to Back to Work, you really should be anyway.)
Anyway, my name is Adam Weeks and I’m the lead mobile developer at Rocksauce Studios. Welcome to my new column “Dev Notes.” I’d like to use these articles to share with you some of the neat things I’ve come across in the development side of things. Being a developer at Rocksauce allows me to work on a multitude of platforms and technologies, but iOS development is what is nearest and dearest to my heart! So that’s where we’ll start!
Almost every app I’ve worked on gets information from the internet in some shape or form. Whether it be downloading weather information, loading a proﬁle picture from Facebook or a full ﬂedged front end for a web service, all these things stream data.
Doing so has not been a simple process. Apple provides a basic web connection class with “NSURLConnection”, to which you have to implement delegate protocols, build your requests, parse your results, handle errors, etc. In other words, it is a lot of work to get it working correctly!
This is where AFNetworking steps in and makes life much easier on you! AFNetworking was actually a product of the Gowalla team that has been make public and available on GitHub. It is built on top of that complicated NSURLConnection and helps to reduce the amount of code needed. It is best to understand the underlying technologies, so please, if you’re just getting started, read through the NSURLConnection documentation before diving into the networking side. Everyone (especially your clients!) will be much happier if you did!
I’m not going to step into any code examples since there are plenty of getting started guides on the AFNetworking site. Instead, I’d like to share with you a few of the ways I’m using it:
• Loading images from the web with the UIImageView category
• Uploading ﬁles and keeping the users informed with a progress indicator
• Fetching and parsing JSON data from a web service like Foursquare or Twitter
• Controlling all access to an API using AFHTTPClient
If you’re an iOS developer, or would like to get into it and need to access the internet in some way, I highly recommend you looking into the AFNetworking library. It will allow you to focus on making your app great instead of spending time trying to ﬁgure out how to download an LOLCAT image.