在我的应用程序中,当我选择一个视频并对其进行压缩后,系统会创建两个文件。当我选择另一个文件时,它会再次复制它。这增加了我的内存空间。现在我想从系统中删除文件的压缩版本。谁能帮我做这件事?
这是我的 ImagePickerController 委托(delegate)
#pragma mark - UIImagePicker delegate
- (void)imagePickerControllerUIImagePickerController *)picker didFinishPickingMediaWithInfoNSDictionary *)info {
NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
if (CFStringCompare ((__bridge CFStringRef) mediaType, kUTTypeMovie, 0) == kCFCompareEqualTo) {
NSURL *videoUrl=(NSURL*)[info objectForKey:UIImagePickerControllerMediaURL];
NSString *moviePath = [videoUrl path];
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath)) {
UISaveVideoAtPathToSavedPhotosAlbum (moviePath, nil, nil, nil);
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
isVideoShooted =NO;
[self navigateToPostAdViewWithURL:videoURL];
}
}
[self dismissViewControllerAnimated:YES completion:^{
}];
}
我得到的videoURL是
file:///Users/webwerks/Library/Developer/CoreSimulator/Devices/17B6B1EB-8015-4747-81B0-6FB07F713471/data/Containers/Data/Application/18A3DB9A-78CE-4761-A4EB-B35CBFCEF1C5/tmp/修剪.A8DC422C-137F-4FF9-878A-E175CE4DDF8F.MOV
当我上传压缩视频时,我正在使用以下代码删除此路径中的文件
+ (void)clearTmpDirectory
{
NSArray* tmpDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:NSTemporaryDirectory() error:NULL];
for (NSString *file in tmpDirectory) {
if ([[file pathExtension]isEqualToString"MOV"])
[[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat"%@%@", NSTemporaryDirectory(), file] error:NULL];
}
}
这段代码运行良好,它从路径中删除了视频,但我仍然在照片应用程序中获得了一个视频文件。每次我上传视频时,都会不断生成文件。现在我不想在照片中创建重复文件,否则它应该在上传后被删除。
Best Answer-推荐答案 strong>
您不必使用 UISaveVideoAtPathToSavedPhotosAlbum 。它会使视频文件被复制。
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath)) {
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
isVideoShooted =NO;
[self navigateToPostAdViewWithURL:videoURL];
}
关于ios - iOS上传后如何删除压缩视频?,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/39874107/
|