Contrast |
Asi |
AFN |
| Update status |
October 2012, the update has been discontinued |
Continuous update, currently updated to version 2.0 |
| Introduced |
The direct Operation object of ASI is a nsoperation subclass that implements the Nscopying protocol ( asihttprequest ). Initialize the related properties in the Initialize and Initwithurl: Methods and configure a list of the default values for request-related parameters. In addition, ASIHTTPRequest provides a series of instance methods to configure the request object. |
AFN's direct Operation object afhttpclientis a nsobject subclass that implements the Nscoding and nscopying protocols. Afhttpclient is a "tool class" that encapsulates a series of action methods, and the action class that handles the request is a series of separate, Nsoperation -encapsulated, afurlconnectionoperation subclasses. |
| Thread handling Mode |
Each request is initialized by a constructor method (shared) instance, which configures the parameters and initiates the request. The ASI initially used the delegate mode callback and provided an instance method for registering the block after the iOS SDK supported block. The ASI takes the Cfhttp request completion, directly callback the ASIHTTPRequest instance method, and completes the callback of the delegate mode or block mode by storing the information recorded by the instance object. On the processing of the asynchronous request, after the initialization of the ASIHTTPRequest object is completed, the object is joined to the shared operations queue in the Startasynchronous method. Thereafter, all operations, including creating Cfhttpmessageref, the primary object that handles the network request (in fact a pointer to the __CFHTTPMESSAGE structure), are done in the child thread to which the ASIHTTPRequest object belongs. |
The AFN example code uses a static method that uses Dispatch_once () to create a shared instance of the Afhttpclient, which is also the official recommended method of use. In the initialization method for creating Afhttpclient, Operationqueue is created and a series of parameter defaults are set. Create a nsurlrequest in the GetPath:parameters:success:failure method to nsurlrequest the object instance as a parameter, create a nsoperation, And joins the Nsoperationqueue created in the initialization sender. The above operations are done in the main thread. In the Start method of Nsoperation, create a nsurlconnection with the Nsurlrequest object created earlier and open the link. |
| data processing mode |
asi is more primitive in this regard, not specifically packaged for any data type, but with a variety of interfaces and tools for developers to extend themselves. |
afn encapsulates the respective processors for JSON, XML, plist, and image four data structures, and the developer can register the processor in the operations queue and get the formatted data directly in the callback method. |
| sync request |
|
afn default does not encapsulate the synchronization request, if the developer needs to use the synchronization request, you need to override the GetPath:parameters:success:failure method to synchronize the afhttprequestoperation with |
| handling of asynchronous callbacks |
even if you use afnetworking to make asynchronous requests to the network in a child thread, Block: (The Void (^) code block is still returned to the UI mainline approached ( AF frame, which already has the create asynchronous thread   ). So The asynchronous return is returned to the main thread of the UI regardless of whether it is currently in the main thread or a child thread. " |
defines a httpclient for a series of related requests, sharing a baseurl. Each request to the URL in addition to the path portion of BaseURL as a parameter passed to HttpClient static method, and register a block for callback. The AFN uses the Completionblock attribute of the nsoperation directly. |
based on the underlying development framework |
|
Nsurl "Using iOS5.0 SDK nsurlconnection: 1, when making a network synchronization request (Sendsynchronousrequest), the operation on which the request interface is invoked, The network results that are returned by the synchronization are in which thread, so usually when a network synchronization request is made, in order to avoid blocking the UI main thread, the network request is made in the child thread, and the Block: (void (^) When the network asynchronous request (Sendasynchronousrequest) is made. The code block is actually returned to the child thread. Therefore, if you need to send a notification to the UI thread at this point, you need to jump to the main thread to send the notification Dispatch_async (Dispatch_get_main_queue (), ^{}); " |
| Bottom development Mining introduction |
Cfnetwork is an underlying high-performance network framework based on Cfstream in Core Foundation, which supports the cfhttp of the HTTP protocol by Cfsocketstream, which provides the underlying services, Cfhttpauthentication based on Cfhttp for identity authentication and CFFTP that support FTP protocol. The Cfsocket in the Core Foundation framework was developed based on BSD sockets. It almost covers the full functionality of the BSD socket and, more importantly, integrates the socket into the event's processing cycle. The higher-level cfstream in Core founda-tion is a read-write stream support based on cfsocket development. |
,asi is a component based on cfhttp development, and AFN's base--nsurl is also based on cfnetwork, which means the ASI is much lower than AFN. |
| performance comparison |
afn request is superior to ASI |
|
| Summarize |
ASI is better suited for applications that have been developing for some time, or for developing resource-rich teams, because often these teams (or their applications) have accumulated some experience, both on the product and on the technical. The complexity of requirements is high up at this time, and the demand for the bottom-line is more and more, at this time AFN is difficult to meet the demand, need to sacrifice a certain ease of use, using ASI as the network underlying control. |
AFN is ideal for logic-simple applications, or for teams that are not rich in development resources, because AFN is much more user-friendly than ASI, and such applications (or teams) have a very low level of customization requirements for the underlying network controls. |