2014-01-24 37 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」不是問題。 –