iOS 将视频保存为livephoto图片,设置为手机动态封面图
2019-12-20 本文已影响0人
流云_henry
/**
将视频转为livephoto保存到本地
@param videoPath 视频地址
@param imagePath 图片地址
@param saveHandle 返回回调
*/
- (void)saveLivePhotoWithVideoPath:(NSString *)videoPath
imagePath:(NSString *)imagePath
handle:(void(^)(BOOL,NSError *))saveHandle;
- (void)saveLivePhotoWithVideoPath:(NSString *)videoPath imagePath:(NSString *)imagePath handle:(void(^)(BOOL,NSError *))saveHandle{
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
PHAssetCreationRequest *creationRequest = [PHAssetCreationRequest creationRequestForAsset];
PHAssetResourceCreationOptions *options = [[PHAssetResourceCreationOptions alloc] init];
[creationRequest addResourceWithType:PHAssetResourceTypePairedVideo fileURL:[NSURL fileURLWithPath:videoPath] options:options];
[creationRequest addResourceWithType:PHAssetResourceTypePhoto fileURL:[NSURL fileURLWithPath:imagePath] options:options];
} completionHandler:^(BOOL success, NSError * _Nullable error) {
saveHandle(success,error);
}];
}