AFNetworking (v3.1.0) framework learning summary (a framework)

Write in first the [written in the previous]

AFNetWorking is the basic standard for the development of iOS network communication framework, the framework itself is relatively large, but also very complex, but very simple to use. Greatly improve the efficiency of development, so that we focus more on the realization of business logic.
like this often use and more important, I think we should know to know the nature of it, and then summarizes the common methods to lay a solid foundation, at last.

Therefore, the spirit of Study hard, understand the authority, decided to start learning from the framework of AFNetworking, according to the function point analysis of each module of it, so I wrote [summary] [+ AFN framework of learning AFN source learning summary series].

This article is mainly from the [AFN]
framework study summary, this book – “Jane ln author of the original” white boiling water; the people you care about, you decided to see the world ^_^.

In the “time & knowledge” is limited, the summary of the article will inevitably have “incomplete, inadequate” place, but also hope that the friends pointed out that in order to improve the quality of the article.

AFNetworking (v3.1.0) framework learning summary (a framework)

Directory: AFN needs | version difference AFN internal architecture of the AFN project directory AFN | follow-up [framework source learning] summary look & About me

First look at the official introduction of AFNetworking, as follows:

AFNetworking is a delightful networking library for iOS and Mac OS X. It’s built on top of the Foundation URL Loading System, extending the powerful high-level networking abstractions built into Cocoa. It has a modular architecture with well-designed, feature-rich APIs that are a joy to use. Perhaps the most important feature of all, however is, the amazing Community of developers who use and contribute to AFNetworking every day. AFNetworking powers some of the most popular and critically-acclaimed apps on the iPhone, iPad and, Mac. Choose AFNetworking for your next project, or migrate over your existing projects you’ll be happy you did!

Simple translation is

AFNetworking is a suitable for iOS and Mac OS X two platform of the network library, which is based on the Foundation URL Loading System on a package, and provides API interface for users to use the rich and beautiful.

Requirements [] demand | version difference

AFNetworking (v3.1.0) framework learning summary (a framework)
AFN –> demand | version difference
  • 1.x version, the internal layer is based on the NSURLConnection, is a NSURLConnection package.
  • In 13 years, Apple launched NSURLSession is session management, then 2.x AFN framework in NSURLSession a package, in fact, is the use of two sets of 2.0-2.6.3 AFN internal system, one is based on NSURLConnection, one is based on NSURLSession.
  • After the upgrade to 3 version, AFN is not in support of NSURLConnection, the URLConnection code has been removed.

Architecture [AFN internal architecture]

  • NSURLSession [manager] AFURLSessionManager AFHTTPSessionManager (packaging commonly used HTTP method) GET POST UIKit + AFNetworking classification NSProgress: using KVO
  • [Serialization] [AFURLRequestSerialization] request serialization serialization (AFHTTPRequestSerializer request data format, the default AFJSONRequestSerializer AFPropertyListRequestSerializer AFURLResponseSerialization binary) [AFHTTPResponseSerializer] (the default response serialized binary response data, analytical solutions (AFJSONResponseSerializer) return type JSON, JSON analytical solutions. The default (AFXMLParserResponseSerializer) return type XML, XML resolution)
  • Additional Functionality [additional features] AFSecurityPolicy [security policy related] HTTPS (HTTP+SSL encryption protocol) AFNetworkReachabilityManager [network status monitoring manager]
  • UIKit [library extensions and tools] UIKit+AFNetworking
  • NSURLConnection (iOS9.0 AFURLConnectionOperation AFHTTPRequestOperation AFHTTPRequestOperationManager (obsolete) package commonly used HTTP methods) for the AFHTTPRequestOperationManager custom attribute baseURL:AFN recommend a single example class, set the baseURL, all network access, only use a relative path: requestSerializer can request data format is the default / HTTP binary response data format: responseSerializer / JSON the default operationQueue format: reachabilityManager operation queue: manager network state detection management method: convenient method to create manager HTTPRequestOperationWithRequest in access to the server, if the server to tell some additional information, you need to set the GET POST in Request

Directory [AFN engineering directory]

The current version is 3.1.0, I import the CocoaPods through the AFNetworking, the directory is as follows

AFNetworking (v3.1.0) framework learning summary (a framework)
CocoaPods–> AFN 3.1.0 engineering directory

After the introduction of the use of CocoaPods can see the directory is very clear mainly in five folders, remove Support Files, you can see the AF is divided into the following 5 functional modules:

  • NSURLSession (network communication module)
  • ReachAbility (network status monitoring module)
  • Security (network communication security policy module)
  • Serialization (network communication information serialization / anti serialization module)
  • UIKit (UIKit library extension)

The core of the network communication module, of course, the rest of the four modules, are in order to cope with network communications or existing UIKit an extension and toolkit. The structural relationships of the classes corresponding to the five modules of the
are shown below:

AFNetworking (v3.1.0) framework learning summary (a framework)
AFN function module –> relationship

You can see that AFN is the core of the AFURLSessionManager class, AFHTTPSessionManager inherited in AFURLSessionManager, for the HTTP protocol to do a specialized transmission. And AFURLResponseSerialization, AFSecurityPolicy, AFNetworkReachabilityManager is used by AFURLSessionManager.
next, you can also see a separate UIKit package provides an extension of the iOS UIKit class library and tools.

can learn under the AFN to do a number of UIKit classification, to enhance their ability to be very helpful.

When the download is good, manually import, display two folders, as follows

AFNetworking (v3.1.0) framework learning summary (a framework)
manual import –> AFN 3.1.0 project directory

It is clear that the first folder is associated with the network request, the second is related to the UI.

Subsequent [follow-up]

This framework has too many things worth learning to study, all aspects of the author and the wisdom of many contributors, we will certainly benefit from reading a lot.

Then, we summarize the framework | source learning [AFN] Road,

  • AFN (v3.0+) framework learning summary (a framework)
  • AFN (v3.0+) framework learning summary (two internal logic processing)
  • AFN (v3.0+) framework learning summary (three basic use of the framework)
  • AFN (v3.0+) framework learning summary (42 package)

Source: according to the AFN 5 functional modules, in turn

  • Network communication core AFURLSessionManager source learning summary
  • HTTP network communication core AFHTTPSessionManager source learning summary
  • Network communication information serialization / anti serialization module AFURL[Request / Response]Serialization source learning summary
  • Network state monitoring module AFNetworkReachabilityManager source learning summary
  • Network security policy AFSecurityPolicy source learning summary
  • AFN provides the function of the toolkit UIKit learning summary


1, can refer to the AFNetworking provided by Example learning

  • AFNetworking reading the source series [Example]
    AFNetworking (v3.1.0) framework learning summary (a framework)
    AFN–> [Example]

2, “HTTPS related”

  • AFNetworking for HTTPS certification
  • Why HTTPS security & analysis of HTTPS connection to establish the whole process
  • What is the knowledge | HTTPS?


  • If you encounter error in the process of reading, I hope you can Issues me, thank you.
  • If you want to share something with this article, I hope you can Issues me, I would like to add more practical content for this article, thank you.
  • “The original blog”, I will continue to update, [not timing, learning experience and practical articles, is the hard truth ^_^.]

About me

I am also a summary of the time spent

I just thought of a [Code] [ape plus your study summary up] to write the article.

AFNetworking (v3.1.0) framework learning summary (a framework)
= “–&gt” code of it; “brother” arrow