Problems deleting video from document directory

混江龙づ霸主 提交于 2019-12-12 04:43:39

问题


I am trying to delete a video from the document directory, but the video isn't deleting.

Here is how I am trying to delete the video:

//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:


You might get a good hint at your problem if you put in a line after your "removeItemAtPath" that says something like:

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



回答2:


Try this instead:

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


来源:https://stackoverflow.com/questions/21322562/problems-deleting-video-from-document-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!