#pragma mark - 保存图片和视频到相册
- (void)saveImageToAlbum:(UIImage*)image
{
if(image)
{
UIImageWriteToSavedPhotosAlbum(image,self,@selector(savedPhotoImage:didFinishSavingWithError:contextInfo:),nil);
}
}
//保存完成后调用的方法
- (void) savedPhotoImage:(UIImage*)image didFinishSavingWithError: (NSError*)error contextInfo: (void*)contextInfo {
if(error) {
NSLog(@"保存图片出错%@", error.localizedDescription);
}
else{
NSLog(@"保存图片成功");
}
}
//videoPath为视频下载到本地之后的本地路径
- (void)saveVideoToAlbum:(NSString*)videoPath
{
if(videoPath) {
BOOL compatible = UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(videoPath);
if(compatible)
{
//保存相册核心代码
UISaveVideoAtPathToSavedPhotosAlbum(videoPath,self,@selector(savedVideoPhotoImage:didFinishSavingWithError:contextInfo:),nil);
}
}
}
//保存视频完成之后的回调
- (void)savedVideoPhotoImage:(UIImage*)image didFinishSavingWithError: (NSError*)error contextInfo: (void*)contextInfo {
if(error) {
NSLog(@"保存视频失败%@", error.localizedDescription);
}
else{
NSLog(@"保存视频成功");
}
}