ios 图片和视频保存到相册

// 保存视频到相册
//path为视频下载到本地之后的本地路径

- (void)saveVideo:(NSString *)path{
    NSURL *url = [NSURL URLWithString:path];
    BOOL compatible = UIVideoAtPathIsCompatibleWithSavedPhotosAlbum([url path]);
    if (compatible) {
            //保存相册核心代码
        UISaveVideoAtPathToSavedPhotosAlbum([url path], self, @selector(video:didFinishSavingWithError:contextInfo:), nil);
    }

}

//保存视频完成之后的回调
- (void)video:(NSString *)videoPath didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
    if (error == NULL) {
         NSLog(@"保存视频成功 %@",videoPath);
    }else{
        NSLog(@"保存视频失败 %@",videoPath);
    }
}

// 保存图片到相册

-(void)takePicProcess:(UIImage*)img{
    UIImage *image = img;
    UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
}

#pragma mark -- <保存到相册>
-(void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
    NSString *msg = nil ;
    if(error){
        msg = @"保存图片失败" ;
    }else{
        msg = @"保存图片成功" ;
        [self performSelectorOnMainThread:@selector(showTakePicResult) withObject:nil waitUntilDone:NO];
    }
    NSLog(@"保存图片====>%@",msg);
}

-(void)showTakePicResult{
    NSLog(@"保存图片成功");
}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容