一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

Error Domain=AVFoundationErrorDomain Code=-11823 "无法存储"

时间:2016-06-18 编辑:简简单单 来源:一聚教程网

在IOS上使用AVFoundation的库进行视频录制,出现错误:

Error Domain=AVFoundationErrorDomain Code=-11823 "无法存储" UserInfo=0x1782f8a00 {NSUnderlyingError=0x17064f4e0 "The operation couldn’t be completed. (OSStatus error -12672.)", AVErrorRecordingSuccessfullyFinishedKey=false, NSLocalizedRecoverySuggestion=请重试存储。, NSLocalizedDescription=无法存储},video.mov -- file:///var/mobile/Applications/D0CA65C7-F218-46F1-80BC-B0FA886EDF3B/Documents/

对于一些英文语言的机器,显示的是:

Error Domain=AVFoundationErrorDomain Code=-11823 "Cannot Save" UserInfo=0x16fb20 {NSLocalizedRecoverySuggestion=Try saving again., NSLocalizedDescription=Cannot Save}

出现Error Domain=AVFoundationErrorDomain Code=-11823这个错误的原因都是需要写文件,但是文件是存在的。不知道为什么ios不允许直接覆盖?在android上,同样的逻辑没有任何问题。

知道问题的原因,那么解决也非常简单,每次再录制视频之前(写文件之前),检查文件是否存在,存在则删除即可:

//如果文件存在,则删除
if ([[NSFileManager defaultManager] fileExistsAtPath:[documentsDirPath stringByAppendingPathComponent:@"video.mp4"]]) {
    NSError *error;
    if ([[NSFileManager defaultManager] removeItemAtPath:[documentsDirPath stringByAppendingPathComponent:@"video.mp4"] error:&error] == NO) {
        NSLog(@"removeitematpath %@ error :%@", [documentsDirPath stringByAppendingPathComponent:@"video.mp4"], error);
    }
}

修改之后,没有任何问题

热门栏目