iOS上传后如何删除压缩视频?

How to delete compressed video after upload in iOS?

在我的应用程序中,当我选择一个视频并在压缩后系统创建两个 files.When 我 select 另一个,它再次复制它。这增加了我的记忆space。现在我想从系统中删除文件的压缩版本。谁能帮我做这件事?

这是我的 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:^{
    }];
}

我得到的视频网址是

file:///Users/webwerks/Library/Developer/CoreSimulator/Devices/17B6B1EB-8015-4747-81B0-6FB07F713471/data/Containers/Data/Application/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];

    }
}

这段代码工作正常,它从路径中删除了视频,但我仍然在照片应用程序中获得了另一个视频文件。每次我上传视频时,这都会不断生成文件。现在我不想在照片中创建重复文件,否则应该在上传后将其删除。

您不必使用 UISaveVideoAtPathToSavedPhotosAlbum。它将使视频文件被复制。

if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath)) {
    NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
    isVideoShooted =NO;
    [self navigateToPostAdViewWithURL:videoURL];
}