App图片批量下载本地和分享

有时候我们需要把很多张图片一次性下载到本地相册或分享到微信朋友圈,此时就需要进行批量操作了

App图片批量下载本地和分享_第1张图片
IMG_F0F6F1DA7588-1.jpeg
Jietu20180801-095931.gif

由于代码量大,我就不在此一一细数了,需要的朋友可以在GitHub下载我的代码阅读

关键代码
//把URL转化成图片存储起来
-(void)urlTiImagesWithCompletionHandler:(void (^)(BOOL isSuccess))completionHandler{
    _imageMuarr = [NSMutableArray new];
    for (int i=0; i<[self imageUrls].count; i++) {
        UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectZero];
        [imageV sd_setImageWithURL:[NSURL URLWithString:[self imageUrls][i]] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
            [self.imageMuarr addObject:image];
            if (self.imageMuarr.count==[self imageUrls].count) {
                completionHandler(YES);
            }
        }];
    }
}
//存储已选的图片
-(NSArray *)selectImages{
    NSMutableArray *muArr = [NSMutableArray new];
    for (int i=0; i<[self imageUrls].count; i++) {
        for (int j=0; j
//保存图片到本地相册
-(void)saveImages{
    if (_imageMuarr.count<[self imageUrls].count) {
        [self urlTiImagesWithCompletionHandler:^(BOOL isSuccess) {
            [self saveImages];
        }];
        return;
    }
    
    NSArray *selectImage = [self selectImages];
    if (selectImage.count==0) {
        [XLImageLoading showAlertInView:self.view message:@"请选择图片"];
        return;
    }
    NSLog(@"***********%@", selectImage);
}

你可能感兴趣的:(App图片批量下载本地和分享)