2014-01-24 51 views
0

我试图从文档目录中删除视频,但视频并未删除。从文档目录中删除视频的问题

这里是我正在试图删除视频:

//Delete Video 
NSError *error = nil; 
//NSData *videoData = [NSData dataWithContentsOfURL:self.finalURL]; 
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *tempPath = [documentsDirectory stringByAppendingFormat:@"/vid1.mp4"]; 
[[NSFileManager defaultManager] removeItemAtPath: tempPath error: &error]; 
UIAlertView *removeSuccessFulAlert=[[UIAlertView alloc]initWithTitle:@"Congratulation:" message:@"Successfully removed" delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil]; 
[removeSuccessFulAlert show]; 

回答

1

你可能在你的问题得到了很好的提示,如果你把一条线的“removeItemAtPath”后,说是这样的:

BOOL success = [[NSFileManager defaultManager] removeItemAtPath: tempPath error: &error]; 
if(!success) 
{ 
    NSLog(@"error from removing item at path %@ is %@", 
     tempPath, [error localizedDescription]); 
} else { 
    UIAlertView *removeSuccessFulAlert=[[UIAlertView alloc]initWithTitle:@"Congratulation:" message:@"Successfully removed" delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil]; 
    [removeSuccessFulAlert show]; 
} 
+0

好了,所以这个记录'从路径在/ var /移动删除项/了Applica错误tions/E5532C71-82BD-4348-AB5E-002A14C975B3/Documents/vid1.mp4 is操作无法完成。 (可可错误4.)' – matthew

+0

@matthew你确定电影文件存在吗? – chancyWu

+0

所以我修复了这个错误。唯一的问题是,当我删除视频时,应用程序占用的空间量会下降,但不会一直到视频拍摄之前的位置。所以它从18开始,然后当一个视频被拍摄时,它会到56,但是当被删除时,它只会下降到20,而不是所有的方式回到18. – matthew

1

试试这个:

NSString *tempPath = [documentsDirectory stringByAppendingPathComponent:@"vid1.mp4"]; 
+0

+1给你正确的方式来追加一个普通的NSString到一个路径的末尾,但我很确定带有零格式参数的“stringByAppendingFormat”不是问题。 –