a brief introduction to afnetworking afnetworking is a in iOS developmentuse very many open source libraries for iOS and Mac OS X. It's built in (Apple iOS development documentation)Nsurlconnection, Nsoperation,and other familiar foundation technologies. It has a good architecture, a rich API, and a modular way of building it, making it easy to use. afurlconnectionoperation: Inherited from Nsoperation implements the Nsurlconnection proxy method. afhttprequestoperation: A subclass that inherits from afurlconnectionoperation, When the protocol used by request requests is HTTP and HTTPS, it encapsulates the status code and the content type used to determine whether the request was successful. afjsonrequestoperation: Inherits from Afhttprequestoperation, which is used to download and process JSON response data. afxmlrequestoperation: inherits from Afhttprequestoperation, which is used to download and process XML response data. afpropertylistrequestoperation: inherited from afhttprequestoperation for downloading and processing property list response data. afhttpclient: is a public communication mode that encapsulates a Web application based on an HTTP protocol. Include 1. Initiatinguse basic URL-dependent paths based on root paths to do only request2. Set HTTP headers for request auto-Add.3. Use the HTTP base certificate or OAuth to verify the request4. Managing a Nsoperationqueue for requests created by client5. Generate a query string or HTTP bodies from Nsdictionary.6. Building multiple parts from request7. Automatic parsing of HTTP response data for corresponding performance data8. Monitor and respond to changes in network accessibility testing.
Note: Official Use document Description: http://cocoadocs.org/docsets/AFNetworking/1.3.0/
two loading into the development environment
1. Download afnetworkinghttps://github.com/AFNetworking/AFNetworking
2. After decompression, drag the Afnetworking folder into Project engineering.
3. Add systemconfiguration and mobilecoreservices frames
4. Add the associated header file to the precompiled header file
#ifdef __objc__
#import<UIKit/UIKit.h>
#import<Foundation/Foundation.h>
#import<SystemConfiguration/SystemConfiguration.h>
#import<MobileCoreServices/MobileCoreServices.h>
#endif
Note: This class library needs to be added in the ARC environment, in non-ARC projects,-fobjc-arc
Four use code
&NBSP; see: https://github.com/zhangzhebjut/iosproject/tree/master/networktool ZZUtilNetWork.h and zzutilnetwork.m are simple packages for afnetworking use.
Summary of five The basic part of afnetworking is Afurlconnectionoperation, which is a nsoperation subclass, the network part is completed by Nsurlconnection, realizes Nsurlconnection The associated proxy method, and then uses the Nsoperation State (isready→isexecuting→isfinished) Change for network control. The network request is completed on a specified thread (networkrequestthread).
Afurlconnectionoperation is a very pure network request operation, can perform start/cancel/pause/resume operation on him, can obtain corresponding nsurlrequest and Nsurlresponse data. Support Nsinputstream/nsoutputstream, provide uploadpress and downloadprogress for other use.
Afhttprequestoperation is a subclass of afurlconnectionoperation that has a layer of encapsulation for the HTTP+HTTPS protocol, such as StatusCode, Content-type, and so on, adding requests The success and failure of the callback block, provides addacceptablecontenttypes: To facilitate the use of the upper layer.