1, drag and drop afnetworking files into the project (note that different versions of the method, the process is based on version 2013);
2, the use of #import "AFNetworking.h" command to include afnetworking.h= in;
3. Complete code:
1 //2 //VIEWCONTROLLER.M3 //Network Requests4 //5 //Created by Mac on 16/5/12.6 //copyright©2016 year MZW. All rights reserved.7 //8 9 #import "ViewController.h"Ten #import "AFNetworking.h" One A @interfaceViewcontroller () - - @end the - @implementationViewcontroller - -- (void) Viewdidload { + [Super Viewdidload]; - + //1. First create a string, connect the base URL and the interface URL. ANSString *urlstring = [@"http://tl.bearapp.cn"Stringbyappendingstring:@"/api/index/zdmc.php"]; at //2. Generate a URL using the string created above -Nsurl *url =[Nsurl urlwithstring:urlstring]; - //3. Create a request Management Object -Afhttprequestoperationmanager *manager = [[Afhttprequestoperationmanager Alloc]initwithbaseurl:url];//If you initialize using the Manager class method here, you should pass in the URL after the get command - //4. Create Parameters -Nsdictionary *DICC = [[Nsdictionary Alloc]initwithobjectsandkeys:@"er sha",@"title", nil]; in //5. Access to resources -[Manager GET:@"SDF"PARAMETERS:DICC success:^ (Afhttprequestoperation *operation,IDresponseobject) { toNSLog (@"%@", Responseobject);//If successful, prints the obtained results +} failure:^ (Afhttprequestoperation *operation, Nserror *error) { -NSLog (@"%@", error);//if it fails, print the wrong information the }]; * $ }Panax Notoginseng - @end
Using afnetworking to request network data in iOS development