[英]UISaveVideoAtPathToSavedPhotosAlbum not saving video to camera roll
我正在尝试使用瞥见来记录UIView。 它已成功将其保存到应用程序的documents文件夹中,但是我还需要将其保存到用户的相机胶卷中。 它没有保存到相机胶卷中,我收到一条警报,允许该应用访问我的相机胶卷,但未保存在任何相册中。
我尝试了很多这样的代码:
[self.glimpse startRecordingView:self.view onCompletion:^(NSURL *fileOuputURL) {
NSLog(@"DONE WITH OUTPUT: %@", fileOuputURL.absoluteString);
UISaveVideoAtPathToSavedPhotosAlbum(fileOuputURL.absoluteString,nil,nil,nil);
}];
对此:
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeVideoAtPathToSavedPhotosAlbum:fileOuputURL
completionBlock:^(NSURL *assetURL, NSError *error){NSLog(@"hello");}];
日志会打印,但不会将视频保存到相机胶卷中。
如果有人对我有任何想法不起作用,请告诉我! 谢谢!
问题在于提供的视频路径。 提供网址的相对路径。
if UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(fileUrl.relativePath) {
UISaveVideoAtPathToSavedPhotosAlbum(fileUrl.relativePath, nil, nil, nil)
}
如果添加了此UIVideoAtPathIsCompatibleWithSavedPhotosAlbum,则编译器将向您显示文件问题。
问题是将您的视频路径指定为URL,因此,您必须检查您的URL路径是否可压缩以保存在视频中,如果您想将视频保存在camara roll中,则只需传递URL并遵循以下代码即可:
-(void)saveVideo:(NSString *)videoData withCallBack:(void(^)(id))callBack{
library = [[ALAssetsLibrary alloc] init];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSData *yourVideoData=[NSData dataWithContentsOfURL:[NSURL URLWithString:videoData]];
if (yourVideoData) {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"video.mp4"];
if([yourVideoData writeToFile:filePath atomically:YES])
{
NSURL *capturedVideoURL = [NSURL URLWithString:filePath];
//Here you can check video is compactible to store in gallary or not
if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:capturedVideoURL]) {
// request to save video in photo roll.
[library writeVideoAtPathToSavedPhotosAlbum:capturedVideoURL completionBlock:^(NSURL *assetURL, NSError *error) {
if (error) {
callBack(@"error while saving video");
NSLog(@"error while saving video");
} else{
callBack(@"Video has been saved in to album successfully !!!");
}
}];
}
}
}
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.