Introduction to AFNetworking in iOS 6

AFNetworking is a light weight, high powerful network library for iOS 6 and mac OSX application development. AFNetworking is a set of wrapper class’s over the top of the NSURLConnection and NSOperation. AFNetworking is powerful to manage all kind of network operations in any manner. AFNetworking can also be compactable for the block operations.
You can download the source code of AFNetworking library from github :- AFNetworking.

According to AFNetworking documentation provide in the github, here I am going to explain how we can get a json data from the webservice.

How to get JSON from a webservice using AFNetworking in iOS6 ?

//Creating NSURL from the String for AFNetworking.
NSURL *url = [NSURL URLWithString:@""];
//Creating NSURLRequest for AFNetworking
NSURLRequest *request = [NSURLRequest requestWithURL:url];
//Creating AFNetworking operation.
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
    NSLog(@" Global Stream: %@", JSON);
} failure:nil];
//starting the server call. 
[operation start];
    AFNetworking Overview:-


AFNetworking Overview in iOS 6

AFNetworking Overview in iOS 6

AFURLConnectionOperation in AFNetworking:-
An NSOperation that implements the NSURLConnection delegate methods.It will handle the server call and its response.

HTTP Requests in AFNetworking
[box type=”shadow”]

1. AFHTTPRequestOperation in AFNetworking.
A subclass of AFURLConnectionOperation for requests using the HTTP or HTTPS protocols. It encapsulates the concept of acceptable status codes and content types, which determine the success or failure of a request.

2. AFJSONRequestOperation in AFNetworking.
A subclass of AFHTTPRequestOperation for downloading and working with JSON response data.

3. AFXMLRequestOperation in AFNetworking.
A subclass of AFHTTPRequestOperation for downloading and working with XML response data.

4. AFPropertyListRequestOperation in AFNetworking.
A subclass of AFHTTPRequestOperation for downloading and deserializing objects with property list response data.


HTTP Client in AFNetworking.

[box type=”shadow”]

1. AFHTTPClient in AFNetworking.
Captures the common patterns of communicating with an web application over HTTP, including:
a)Making requests from relative paths of a base URL
b)Setting HTTP headers to be added automatically to requests
c)Authenticating requests with HTTP Basic credentials or an OAuth token
d)Managing an NSOperationQueue for requests made by the client
e)Generating query strings or HTTP bodies from an NSDictionary
f)Constructing multipart form requests
g)Automatically parsing HTTP response data into its corresponding object representation
h)Monitoring and responding to changes in network reachability


you can read detailed implementation form here











No Comments

Leave a Reply

Your email address will not be published. Required fields are marked *