从文档目录中删除视频的问题

时间:2014-01-24 01:09:49

标签: ios video nsdocumentdirectory

我正在尝试从文档目录中删除视频,但视频未删除。

以下是我尝试删除视频的方式:

//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];

2 个答案:

答案 0 :(得分: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];
}

答案 1 :(得分:1)

请改为尝试:

NSString *tempPath = [documentsDirectory stringByAppendingPathComponent:@"vid1.mp4"];
相关问题