// 异步下载图片

        dispatch_queue_t queue =dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0);

        dispatch_group_t group =dispatch_group_create();

        dispatch_group_async(group, queue, ^{

            NSData *data = [NSDatadataWithContentsOfURL:[NSURLURLWithString:imageUrl]];

            UIImage *image = [UIImageimageWithData:data];

                //  保存图片到相册

                [PDPhotoGraphToolsaveImageToPhotos:image];

        });

 

 

 

@interface PDPhotoGraphTool: NSObject

 

+ (void)saveImageToPhotos:(UIImage *)savedImage;

 

 

+ (void)image: (UIImage *) image didFinishSavingWithError: (NSError *) errorcontextInfo: (void *) contextInfo;

@end

 

 

@implementationPDPhotoGraphTool

 

+(void)saveImageToPhotos:(UIImage *)savedImage

{

   

    UIImageWriteToSavedPhotosAlbum(savedImage,self,@selector(image:didFinishSavingWithError:contextInfo:),NULL);

}

 

+(void)image:(UIImage *)image didFinishSavingWithError:(NSError *)errorcontextInfo:(void *)contextInfo

{

    NSString *msg = nil ;

   

    if(error != NULL){

       

        msg = @"保存图片失败" ;

       

    }else{

       

        msg = @"保存图片成功" ;

       

    }

   

    UIAlertView *alert = [[UIAlertViewalloc] initWithTitle:@"保存图片结果提示"

                         

                                                   message:msg

                         

                                                  delegate:self

                         

                                          cancelButtonTitle:@"确定"

                         

                                          otherButtonTitles:nil];

   

    [alert show];

 

}

@end

相关文章:

  • 2021-11-06
  • 2021-08-04
  • 2021-11-05
  • 2021-11-24
  • 2021-11-03
  • 2021-11-08
  • 2021-11-13
猜你喜欢
  • 2021-10-17
  • 2021-10-14
  • 2021-11-08
  • 2021-12-27
  • 2021-12-13
  • 2018-09-04
  • 2021-11-06
  • 2021-06-25
相关资源
相似解决方案