AFNETWORKING3.0 is the latest version, originally intended to introduce 2.6, but think about 2.6 soon, decided not to introduce, interested in a small partner can surf the internet to check. I'm going to get to the bottom of it.
There is no one of the third-party network libraries currently using the largest number. From the beginning of the nsurlconnection to the present nsurlsession, it has been maintained with the Apple unison, and it also derived a large number of related third-party network function library, not only because of his reliable, easy to use, has maintained a maintenance update, It is also why it is so favored by the vast number of programmers.
Upload data
viewcontroller.m//cx-afnetworking3.0 Introduction////Created by Ma C on 16/3/22.//Copyright? 2016 Xubaoaichiyu. All rights reserved.//#import "ViewController.h" #import "AFNetworking.h" @interface Viewcontroller () @ End@implementation viewcontroller-(void) viewdidload {[Super viewdidload]; [Self uploaddata]; }//upload data-(void) uploaddata{UIImage * image = [UIImage imagenamed:@ "renminbi.jpg"]; NSData * data = uiimagejpegrepresentation (image, 1); Afhttpsessionmanager * Manager = [Afhttpsessionmanager manager]; /* POST upload Address Parameters text parameter Constructingbodywithblock upload file block, there may be multiple calls progress upload progress success upload success Failure upload failed */[manager post:@ "http://localhost/post/upload.php" Parameters:nil constructingbodywithblock:^ (id& Lt Afmultipartformdata> _nonnull formData) {/* FormData uploaded data FileData The data name of the uploaded file is the name on the key FileName server where the file was uploaded MimeType type of upload resource */[FormData appendpartwithfiledata:data name:@ "userfile00" FileName : @ "Xubaoaichiyu" mimetype:@ "image/jpg"]; } progress:^ (Nsprogress * _nonnull uploadprogress) {NSLog (@ "%@", uploadprogress); } success:^ (Nsurlsessiondatatask * _nonnull task, id _nullable responseobject) {NSLog (@ "Success->%@", Respon Seobject); } failure:^ (Nsurlsessiondatatask * _nullable task, Nserror * _nonnull error) {NSLog (@ "Failed->%@", error); }]; } @end
Uploading files
Upload file Afhttpsessionmanager * manager = [Afhttpsessionmanager manager]; /* POST upload Address Parameters text parameter Constructingbodywithblock upload file block, there may be multiple calls progress upload progress success upload success Failure upload failed */[manager post:@ "http://localhost/post/upload.php" Parameters:nil constructingbodywithblock:^ (id& Lt Afmultipartformdata> _nonnull formData) {/* FormData uploaded data FileData upload File The data name of the upload file on the key FileName server name MimeType upload Resources Type */nsurl * URL = [[NSBundle mainbundle] urlforresource:@ "Renminbi.jpg" withextension:n IL]; [FormData appendpartwithfileurl:url name:@ "userfile00" filename:@ "Xubaoaichiyu" mimetype:@ "image/jpg" error:nil]; } progress:^ (Nsprogress * _nonnull uploadprogress) {NSLog (@ "%@", uploadprogress); } success:^ (Nsurlsessiondatatask * _nonnullTask, id _nullable responseobject) {NSLog (@ "Success->%@", Responseobject); } failure:^ (Nsurlsessiondatatask * _nullable task, Nserror * _nonnull error) {NSLog (@ "Failed->%@", error); }];
Get
Afhttpsessionmanager * Manager = [Afhttpsessionmanager manager]; [Manager get:@ "http://localhost/post/upload.php" Parameters:nil progress:^ (nsprogress * _nonnull downloadprogress) { } success:^ (Nsurlsessiondatatask * _nonnull task, id _nullable responseobject) { } failure:^ ( Nsurlsessiondatatask * _nullable task, Nserror * _nonnull error) { }];
Post
Afhttpsessionmanager * Manager = [Afhttpsessionmanager manager]; [Manager post:@ "http://localhost/post/upload.php" Parameters:nil progress:^ (nsprogress * _nonnull downloadprogress) { } success:^ (Nsurlsessiondatatask * _nonnull task, id _nullable responseobject) { } failure:^ ( Nsurlsessiondatatask * _nullable task, Nserror * _nonnull error) { }];
GetXML
Afhttpsessionmanager * Manager = [Afhttpsessionmanager manager]; Manager.requestserializer = [Afhttprequestserializer serializer]; Manager.responseserializer = [Afxmlparserresponseserializer serializer]; [Manager get:@ "http://localhost/post/upload.php" Parameters:nil progress:^ (nsprogress * _nonnull downloadprogress) { } success:^ (Nsurlsessiondatatask * _nonnull task, id _nullable responseobject) { } failure:^ ( Nsurlsessiondatatask * _nullable task, Nserror * _nonnull error) { }];
An analysis of the IOS network-(Eleven-Three party AFNetworking3.0 Introduction)