An analysis of the IOS network-(Eleven-Three party AFNetworking3.0 Introduction)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.