在我的应用程序中,当我选择一个视频并在压缩之后,系统会创建两个文件。当我选择另一个文件时,它再次复制它。这增加了我的记忆空间。现在我想从系统中删除压缩版本的文件。有人可以帮我这样做吗?
这是我的ImagePickerController委托
#pragma mark - UIImagePicker delegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)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是
文件:///用户/ webwerks /库/开发商/ CoreSimulator /设备/ 17B6B1EB-8015-4747-81B0-6FB07F713471 /数据/容器/数据/应用/ 18A3DB9A-78CE-4761-A4EB-B35CBFCEF1C5 / TMP / trim.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];
}
}
此代码可以正常删除路径中的视频,但我仍然可以在照片应用中再获取一个视频文件。每次上传视频时都会连续生成文件。现在我想不在照片中创建重复文件,或者在上传后它应该被删除。
答案 0 :(得分:2)
您不必使用UISaveVideoAtPathToSavedPhotosAlbum
。它会使视频文件重复。
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath)) {
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
isVideoShooted =NO;
[self navigateToPostAdViewWithURL:videoURL];
}