"iOS Development Tour" afnetworking and sdwebimage download pictures

Source: Internet
Author: User

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

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.