我的应用程序正在使用UIImagePickerController录制视频并将其保存到相机胶卷,但我的问题是录制的视频也保存在/ tmp / capture目录中并且不会被删除。由于这个原因,我的应用程序使用大量不必要的数据慢慢累积存储在tmp / capture目录中的一长串视频。我正在使用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文件夹中,如何阻止它执行此操作?
由于
答案 0 :(得分:4)
上传完成后,您需要删除包含电影的目录(这也会删除临时文件):
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]);
}
}