#import "AFNetworking.h"//used primarily for network request methods #import "Uikit+afnetworking.h"//inside there is a way to load images asynchronously
-(void) obtaindata{ // starter system steam wheel [UIApplication sharedapplication].networkactivityindicatorvisible = yes; //in front of the server to write the domain name, the following stitching on the need to submit parameters, if the parameters are key=1 nsstring *domainstr = @ "http://192.168.1.69/xffcol/index.php/Api/key/1/"; afhttprequestoperationmanager *manager = [afhttprequestoperationmanager manager]; manager.responseSerializer = [AFHTTPResponseSerializer serializer]; //is submitted in the form of get, only the above request address to get parameters can be [manager get:domainstr parameters:nil success:^ (afhttprequestoperation *operation, id Responseobject) { // hidden system steam Wheel [uiapplication sharedapplication].networkactivityindicatorvisible = no; //json Analysis nsdictionary *resultdic = [nsjsonserialization jsonobjectwithdata:responseobject options:nsjsonreadingmutableleaves error:nil]; nslog (@ "---gets to the JSON-formatted dictionary--%@", Resultdic); } failure:^ (Afhttprequestoperation *operation, nserror *error) { // Parse failed hidden system steam wheel (can print error.userinfo view error message) [UIApplication sharedapplication].networkactivityindicatorvisible = no; }];}
-(void) obtaindata{ // starter system steam wheel [UIApplication sharedapplication].networkactivityindicatorvisible = yes; //server to the domain name nsstring *domainstr = @ "http://192.168.1.69/xffcol/index.php/Api/"; // If the parameter that needs to be submitted to the server is key=1,class_id=100 //create a mutable dictionary nsmutabledictionary *parametersdic = [nsmutabledictionary dictionary]; // Add the required parameters to the dictionary [parametersdic setobject:@ "1" forkey:@ "key"]; [parametersdic setobject:@ " forkey:@" class_id "]; AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager Manager]; manager.responseserializer = [afhttpresponseserializer serializer]; // Submitted as a post, the parameters of the post is the domain name above, the parameters parameter is a dictionary type, the above dictionary as its parameter [manager post: domainstr parameters:parametersdic success:^ (afhttprequestoperation *operation, id Responseobject) { // hidden system steam Wheel [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; //json Analysis NSDictionary *resultDic = [NSJSONSerialization jsonobjectwithdata:responseobject options:nsjsonreadingmutableleaves error:nil]; nslog (@ "---gets to the JSON-formatted dictionary--%@", Resultdic); } failure:^ (afhttprequestoperation *operation, nserror * Error) { // Parse failed hide system steam wheel (can print error.userinfo view error message) [uiapplication sharedApplication].networkActivityIndicatorVisible = NO; }];}
-(void) uploadpictures{ //domain name nsstring *domainstr = @ "http://192.168.1.69/xffcol/index.php/Api/"; AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; manager.responseserializer = [afhttpresponseserializer serializer]; //If you need to upload additional parameters, refer to the POST request above, create a mutable dictionary, and deposit the contents of the parameters that need to be submitted. Submit as parameter of parameters [manager POST:domainStr parameters:nil constructingbodywithblock:^ (Id<afmultipartformdata> formdata) { //_imagearray is the image array, my _imagearray is stored in the image of the data, the following can be directly removed to use, if the memory is an image, Convert image to data as follows: Nsdata *imagedata = uiimagejpegrepresentation (image, 0.7); if (_imagearray.count > 0 ) { for (int i = 0;i < _imagearray.count;i ++) { NSData *data=_imageArray[i]; //the name of the parameter being uploaded nsstring *name = [nsstring stringwithformat:@ "%d",i]; //uploaded by filename nsstring *filename = [ nsstring stringwithformat:@ "%@.jpg",name]; [formData appendPartWithFileData:data name: name fileName:fileName mimetype:@ "Image/jpeg"]; } } }success:^ (Afhttprequestoperation *operation, id responseobject) { //shut down system steam wheel [uiapplication sharedapplication].networkactivityindicatorvisible = NO; //json Analysis NSDictionary * Resultdic = [nsjsonserialization jsonobjectwithdata:responseobject options: nsjsonreadingmutableleaves error:nil]; nslog (@ "---resultdic--%@", resultDic); } failure:^ (Afhttprequestoperation *operation, nserror *error) { // parsing Failure [uiapplication sharedapplication]. networkactivityindicatorvisible = no; }];}
[Leftview setimagewithurl:[nsurl urlwithstring:@ "Http://pic25.nipic.com/20121205/5955207_182136452000_2.jpg"] placeholderimage:@ "Here is the default image displayed when the network image is not loaded yet";
Basic use of iOS development afnetworking