UIImagePickerController不会从/ tmp / capture中删除临时video捕获文件

我的应用程序使用UIImagePickerController录制video并将其保存到相机胶卷上,但问题是录制的video也保存在/ tmp / capture目录中,不会被删除。 我的应用程序使用很多不必要的数据,因此缓慢地累积了存储在tmp / capture目录中的一长串video。 我正在使用ARC和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。

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

为什么应用程序每次都将文件保存到tmp文件夹,我该如何阻止它呢?

谢谢

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

 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]); } }