码迷,mamicode.com
首页 > 其他好文 > 详细

下载图片,

时间:2014-06-24 10:59:35      阅读:231      评论:0      收藏:0      [点我收藏+]

标签:class   http   tar   com   get   string   

-(void)downImage

{

    AlbumInfo *info = [self.dataArray objectAtIndex:index];

    NSString *filePath = [[SandBoxPath pathForCaches]stringByAppendingPathComponent:@"/a.png"];

    [self showLoadingView];

    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:info.url]];

    AFDownloadRequestOperation *downloadOperation = [[AFDownloadRequestOperation alloc]initWithRequest:request targetPath:filePath shouldResume:NO];

    [downloadOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {

        [self hideLoadingView];

        UIImage *image = [UIImage imageWithContentsOfFile:filePath];

        if (image) {

            UIImageWriteToSavedPhotosAlbum(image, self, nil, NULL);

            [self showToast:@"保存成功!"];

        }else{

            [self showToast:@"保存失败!"];

        }

        

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

        [self hideLoadingView];

        [self showToast:@"保存失败!"];

 

    }];

    

    [downloadOperation setProgressiveDownloadProgressBlock:^(AFDownloadRequestOperation *operation, NSInteger bytesRead, long long totalBytesRead, long long totalBytesExpected, long long totalBytesReadForFile, long long totalBytesExpectedToReadForFile) {

        TTLog(@"bytesread: %d",bytesRead);

    }];

    NSOperationQueue *downloadQueue = [[NSOperationQueue alloc]init];

    [downloadQueue addOperation:downloadOperation];

}

下载图片,,布布扣,bubuko.com

下载图片,

标签:class   http   tar   com   get   string   

原文地址:http://www.cnblogs.com/guligei/p/3804374.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!