iOS 之網路下載圖片
////網路下載圖片方法一:
//處理圖片url---下載圖片---儲存圖片到相簿
//-(void)dealDownloadImageStr{
// dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
// dispatch_semaphore_t semaphore = dispatch_semaphore_create(1);//*******建立訊號量
// if(self.bigImage &&![self.bigImage isEqualToString:@""]){
// [[LYCommonMBprogresshud sharedManager]showProgresshudAnimalWith:self.view title:@"正在下載" detailtitle:@"" isOnDismissbg:NO hideAfterdelay:NO];
// NSMutableArray * bigImageArrs=[[NSMutableArray alloc]initWithArray:[self.bigImage componentsSeparatedByString:@","]];
// for (int i=0; i<bigImageArrs.count; i++) {
// dispatch_async(queue, ^{
// NSString *url=[WOFUBASEURL stringByAppendingString:bigImageArrs[i]];
// NSLog(@"url-我的--%@",url);
// [_bigImageArr addObject:url];
// if([url containsString:@"jpg"] || [url containsString:@"jpeg"]|| [url containsString:@"png"]){
// dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);//******減少訊號量
// self.index=i;
// NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
// UIImage *image=[UIImage imageWithData:data];
// UIImageWriteToSavedPhotosAlbum(image,self,@selector(imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:),nil);//儲存圖片到相簿
// }else {
// //不是圖片,下載不了
//
// }
// dispatch_semaphore_signal(semaphore);//*********增加訊號量
// });
// }
// }else{
//
// [[LYCommonMBprogresshud sharedManager]showProgresshudTextWith:self.view title:@"沒有可下載的素材" detailtitle:@"" isOnDismissbg:NO hideAfterdelay:YES];
// }
//}
////儲存圖片到相簿的代理方法
//- (void)imageSavedToPhotosAlbum:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
//{
// [[LYCommonMBprogresshud sharedManager]dimisAnimalProgressWith:self.view];
// if (!error) {
// NSString *message=[NSString stringWithFormat:@"第%tu張圖片儲存成功",self.index+1];
// [[LYCommonMBprogresshud sharedManager]showProgresshudTextWith:self.view title:message detailtitle:@"請到相簿檢視" isOnDismissbg:NO hideAfterdelay:YES];
//
// }else{
// NSString *message=[NSString stringWithFormat:@"第%tu張圖片儲存失敗",self.index+1];
// [[LYCommonMBprogresshud sharedManager]showProgresshudTextWith:self.view title:message detailtitle:@"請重試" isOnDismissbg:NO hideAfterdelay:YES];
// }
//}
//方法二:SDWebImage 下載 #import <SDWebImageDownloader.h>
////sdweb下載圖片**********
//-(void)sdwebDownloadWithimageStr:(NSString *)imageUrl{
// if(imageUrl && ![imageUrl isEqualToString:@""]){
// __weak typeof(self) weakSelf=self;
// SDWebImageDownloader *downloader = [SDWebImageDownloader sharedDownloader];
// [downloader downloadImageWithURL:[NSURL URLWithString:imageUrl]
// options:0
// progress:^(NSInteger receivedSize, NSInteger expectedSize) {
//
// }
// completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
// if (image && finished) {
// //縮小圖片
// CGSize newSize=CGSizeMake(118, 118);
// UIGraphicsBeginImageContext(newSize);
//
// [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
//
// image= [UIGraphicsGetImageFromCurrentImageContext() imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];//從圖形上下文獲取新的圖片
// UIGraphicsEndImageContext();
// [self.imageIMArr addObject:image];
// if(self.imageIMArr.count==self.dataArr.count){
// [self.tab reloadData];
// NSLog(@"sdwebxiazai ");
// [weakSelf.tab.header endRefreshing];
//
// }
// }
// }];
// }else {
// UIImage *image=[UIImage imageNamed:@"appstart"];
// [self.imageIMArr addObject:image];
// if(self.imageIMArr.count==self.dataArr.count){
// [self.tab reloadData];
// [self.tab.header endRefreshing];
// }
// }
//
//}