问题
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