Xcode 7 ATS设置
这两天研究SDWebimage库,在xode 7上运行过程中遇到了些问题,创建的新项目由于使用到了https的图片URL,运行后,怎么都不出现图片,发送请求时,报下面的错:
“App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app’s Info.plist file”
经过搜索stackoverflow查询相关问题发现,iOS9新特性要求App内访问网络请求要采用HTTPS协议,无论url是http的还是https的。通过进行如下设置即可:
|
然后尝试了SDWebimage不同的图片加载方法,均成功展示。后面可以正常研究图片缓存的实现了。
/** * Using SDWebimage */ NSURL *imgURL = [NSURL URLWithString:@"http://www.sogou.com/images/logo/new/sogou.png"];
// Using UIImageView+WebCache category [imageView sd_setImageWithURL:imgURL placeholderImage:[UIImage imageNamed:@"default_pic"]];
// Using blocks [imageView sd_setImageWithURL:imgURL placeholderImage:[UIImage imageNamed:@"default_pic"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
}];
// Using SDWebImageManager SDWebImageManager *manager = [SDWebImageManager sharedManager]; [manager downloadImageWithURL:imgURL options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize) { // progression tracking code } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { if (image) { // do something with image [imageView setImage:image]; } }];
// Using Asynchronous Image Downloader Independently SDWebImageDownloader *downloader = [SDWebImageDownloader sharedDownloader]; [downloader downloadImageWithURL:imgURL options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize) { // progression tracking code } completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) { if (image && finished) { // do something with image [imageView setImage:image]; } }]; |