【问题标题】:Problems deleting video from document directory从文档目录中删除视频的问题
【发布时间】:2014-02-14 20:24:34
【问题描述】:

我正在尝试从文档目录中删除一个视频,但该视频没有被删除。

这是我尝试删除视频的方法:

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

【问题讨论】:

    标签: ios video nsdocumentdirectory


    【解决方案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];
    }
    

    【讨论】:

    • 好的,所以这会记录error from removing item at path /var/mobile/Applications/E5532C71-82BD-4348-AB5E-002A14C975B3/Documents/vid1.mp4 is The operation couldn’t be completed. (Cocoa error 4.)
    • @matthew 你确定电影文件存在吗?
    • 所以我已经修复了这个错误。唯一的问题是,当我删除视频时,应用程序占用的空间量会下降,但不会一直下​​降到拍摄视频之前的位置。所以它从 18 开始,然后当拍摄视频时,它会变为 56,但删除后它只会下降到 20 左右,而不是一直回到 18。
    • 我认为这个错误只是发生了一些奇怪的事情,因为它只发生过一次。
    • @matthew 通常 Cocoa 错误 4 表示文件不存在。
    【解决方案2】:

    试试这个:

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

    【讨论】:

    • +1 为您提供将普通 NSString 附加到路径末尾的正确方法,但我很确定带有零格式参数的“stringByAppendingFormat”不是问题。
    猜你喜欢
    • 1970-01-01
    • 2023-04-03
    • 2015-03-28
    • 2011-08-06
    • 2013-02-07
    • 2011-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多