【发布时间】:2013-12-12 02:02:24
【问题描述】:
我的应用正在使用 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 文件夹,我该如何阻止它这样做?
谢谢
【问题讨论】:
标签: ios iphone memory uiimagepickercontroller