ios - ios UIImagePickerController不从/tmp/capture 删除临时视频捕获文件

  显示原文与译文双语对照的内容
95 5

我的应用程序正在使用UIImagePickerController录制视频并将它的保存到相机卷上,但问题是录制的视频也存储在/tmp/capture 目录中。我的应用程序使用大量不必要的数据将存储在 tmp/catch目录中的长期视频累积很长。我正在使用 arc 和 ios 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; 我把它们设置为空一旦完成。

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

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

谢谢

时间:原作者:0个回答

82 1

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

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]);
 }
}
原作者:
...