UIImagePickerController不会从/tmp/capture删除临时视频捕获文件 [英] UIImagePickerController doesn't delete temp video capture file from /tmp/capture

查看:98
本文介绍了UIImagePickerController不会从/tmp/capture删除临时视频捕获文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序正在使用UIImagePickerController录制视频并将其保存到相机胶卷中,但是我的问题是录制的视频也被保存在/tmp/capture目录中并且不会被删除.因此,我的应用程序会使用大量不必要的数据慢慢累积一长串存储在tmp/capture目录中的视频.我正在使用ARC和iOS7 SDK.

My app is recording videos using a UIImagePickerController and saves it to the camera roll just fine but my problem is that the recorded video is also being saved in the /tmp/capture directory and doesn't get deleted. My app slowly accumulates a long list of videos stored in the tmp/capture directory using lots of unnecessary data because of this. I am using ARC and iOS7 SDK.

-(BOOL)startCameraControllerFromViewController:(UIViewController*)controller       usingDelegate:(id )delegate forType: (int)type 
{ 
    if (([UIImagePickerController     isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] == NO)
    || (delegate == nil)
    || (controller == nil)) {
    return NO;
    }

    UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
    cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;

    if(type == IMAGE )
        cameraUI.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeImage, nil];
     if(type == VIDEO)
     {
         cameraUI.videoMaximumDuration = 60.0f;
         cameraUI.videoQuality = UIImagePickerControllerQualityType640x480; 
         cameraUI.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
     }
     cameraUI.allowsEditing = NO;
     cameraUI.delegate = delegate;
     [controller presentViewController: cameraUI animated: YES completion:nil];
     return YES;
}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

 {   
     NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];

     if(CFStringCompare ((__bridge_retained CFStringRef)mediaType, kUTTypeMovie, 0) == kCFCompareEqualTo)//video
     {
         NSString *moviePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];

         if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(moviePath)) 
             UISaveVideoAtPathToSavedPhotosAlbum(moviePath,   self,@selector(video:didFinishSavingWithError:contextInfo:), nil);

         [self dismissViewControllerAnimated:NO completion:nil];
         globalDel.videoPath = moviePath;
         globalDel.videoToUpload = [NSData dataWithContentsOfFile:moviePath];
     }
}

globalDel.videoPath定义为:@property(nonatomic,retain)NSString * videoPath; globalDel.videoToUpload定义为:@property(nonatomic,retain)NSData * videoToUpload; 完成后,我将它们设置为NULL.

globalDel.videoPath is defined as: @property(nonatomic,retain)NSString *videoPath; globalDel.videoToUpload is defined as: @property(nonatomic,retain)NSData *videoToUpload; I set them to NULL once done with them.

我使用委托文件来保留这些引用以在不同的导航控制器之间使用.

I use a delegate file to keep those references for use between different navigation controllers.

为什么应用程序每次都会将文件保存到tmp文件夹中?如何阻止它执行该操作?

Why is the app saving the file to the tmp folder each time and how do I stop it from doing that?

谢谢

推荐答案

上传完成后,您需要删除包含电影的目录(这也会删除临时文件):

You need to delete the directory containing the movie once your upload is finished (which will also delete the temp file):

NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:globalDel.videoPath]) {
    NSError *error;
    // Attempt to delete the folder containing globalDel.videoPath
    if ([fileManager removeItemAtPath:[globalDel.videoPath stringByDeletingLastPathComponent] error:&error] != YES) {
        NSLog(@"Unable to delete file: %@", [error localizedDescription]);
    }
}

这篇关于UIImagePickerController不会从/tmp/capture删除临时视频捕获文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆