afnetworking and sdwebimage Download pictures
////VIEWCONTROLLER.M//Afnetworkingdemo////Created by chenqianping on 16/1/31.//copyright©2016 year CHENQP. All rights reserved.//#import "ViewController.h"#import "AFNetworking.h"#import "uiimageview+webcache.h"//originally because of iOS9, the original HTTP protocol was changed to the HTTPS protocol, using TLS1.2 SSL encryption request data. #defineIMAGEURL @ "http://Www.sanguosha.com/images/23/123/1107/26/12/9458_10132412.PNG "@interfaceViewcontroller ()@end@implementationViewcontroller//afnetworking way to download pictures//get a picture of a network and load it into a local//The network downloads the data, then turns the data into pictures, then loads- (void) picture1{Uiimageview*iv =[[Uiimageview Alloc]initwithframe:[uiscreen mainscreen].bounds]; [Self.view Addsubview:iv]; Afhttprequestoperationmanager*manager =[Afhttprequestoperationmanager Manager]; Manager.responseSerializer.acceptableContentTypes= [Nsset setwithobject:@"Image/png"]; [Manager Get:imageurl Parameters:nil success:^ (Afhttprequestoperation *operation,IDresponseobject) {NSLog (@"Download the picture Successfully!"); Iv.image=[UIImage ImageWithData:operation.responseData]; }failure:^ (Afhttprequestoperation *operation,nserror *error) {NSLog (@"%@", error); }];}//sdwebimage way to download pictures- (void) picture2{Uiimageview*iv =[[Uiimageview Alloc]initwithframe:[uiscreen mainscreen].bounds]; [Self.view Addsubview:iv]; [IV Sd_setimagewithurl:[nsurl Urlwithstring:imageurl];}- (void) viewdidload {[Super viewdidload];//[self picture1];[self picture2];}- (void) didreceivememorywarning {[Super didreceivememorywarning]; //Dispose of any resources the can be recreated.}@end
Info.plist settings
"iOS Development Tour" afnetworking and sdwebimage download pictures