AVFoundationErrorDomain Code=-11800, An unknown error occurred (-12780)

这篇博客介绍了在遇到AVFoundationErrorDomain错误,具体代码为-11800和-12780时的解决方法。问题在于尝试将PHAsset保存到沙盒特定路径时发生。博主建议首先确认路径是否正确,特别是AVAssetExportSession的outputURL应使用fileURLWithPath而非URLWithString。提供了完整的代码示例以供参考。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

期望:

PHAsset 保存到沙盒指定目录

实现方法:

- (PHImageRequestID)requestExportSessionForVideo:(PHAsset *)asset options:(nullable PHVideoRequestOptions *)options exportPreset:(NSString *)exportPreset resultHandler:(void (^)(AVAssetExportSession *__nullable exportSession, NSDictionary *__nullable info))resultHandler;

结果:

Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedFailureReason=An unknown error occurred (-12780), NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x28208c600 {Error Domain=NSOSStatusErrorDomain Code=-12780 "(null)"}}

原因:

  优先检查路径,AVAssetExportSession的属性outputURL 为[NSURL fileURLWithPath:path], 而不是 [NSURL URLWithString:path].

完整代码如下:

//PHAsset 的扩展方法
- (void)saveVideoDataWithFileName:(NSString *)fileName finish:(void(^)(BOOL saveOk))completion {
    //确定保存路径
    NSString *directory = GVUSER.isLockedAlbum? DIRECTORY_VIDEO_LOCK : DIRECTORY_VIDEO;
    NSString *path = [directory stringByAppendingPathComponent:fileName];
    BOOL fileExist = [FILEMANAGER fileExistsAtPath:path];
    if (!fileExist) {
        PHVideoRequestOptions *option = [[PHVideoRequestOptions alloc] init];
        option.version = PHVideoRequestOptionsVersionOriginal;
        option.deliveryMode = PHVideoRequestOptionsDeliveryModeHighQualityFormat;
        option.networkAccessAllowed = YES;
        [PHImageManager.defaultManager requestExportSessionForVideo:self options:option exportPreset:AVAssetExportPresetHighestQuality resultHandler:^(AVAssetExportSession * _Nullable exportSession, NSDictionary * _Nullable info) {
            exportSession.outputFileType = AVFileTypeMPEG4;
            exportSession.outputURL = [NSURL fileURLWithPath:path];
            [exportSession exportAsynchronouslyWithCompletionHandler:^{
                // 如果导出的状态为完成
                if ([exportSession status] == AVAssetExportSessionStatusCompleted) {
                    //保存完成
                    completion(YES);
                }else if (exportSession.status == AVAssetExportSessionStatusFailed){
                    NSLog(@"错误0----%@",exportSession.error);
                    completion(NO);
                }
            }];
        }];
    }else {
        NSString *newFileName = fileName.fixedFileName;
        [self saveVideoDataWithFileName:newFileName finish:^(BOOL saveOk) {
            completion(saveOk);
        }];
    }
}

//NSString 的扩展方法
- (NSString *)fixedFileName {
    NSString *newFileName;
    NSArray *coms = [self componentsSeparatedByString:@"."];
    //有格式显示
    if (coms.count > 1) {
        NSString *fileFormat = coms.lastObject;
        //        NSString *pureName = coms[coms.count-2];
        NSString *dotFormat = [@"." stringByAppendingString:fileFormat];
        NSString *pureName = [self stringByReplacingOccurrencesOfString:dotFormat withString:@""];
        NSString *newPureName;
        if ([pureName hasSuffix:@")"]) {
            //有(*)
            if (pureName.length > 1) {
                NSString *num = [pureName substringWithRange:NSMakeRange(pureName.length-2, 1)];
                NSString *newNum = [NSString stringWithFormat:@"%ld", (long)(num.integerValue+1)];
                newPureName = [pureName stringByReplacingOccurrencesOfString:num withString:newNum];
            }else {
                newPureName = [pureName stringByAppendingString:@"1"];
            }
            newFileName = [NSString stringWithFormat:@"%@.%@", newPureName, fileFormat];
        }else {
            newFileName = [NSString stringWithFormat:@"%@(1).%@", pureName, fileFormat];
        }
    }

    //没有格式显示
    else {
        newFileName = [self stringByAppendingString:@"(1)"];
    }
    return newFileName;
}

转载于:https://www.cnblogs.com/binbins/p/10860960.html

ipa equestOrder IOS 14.8 版本手机报错,信息如下,其他版本不报错。 equestOrder failed: {"code":0,"message":"Payment_appleiap:Error Domain=SKErrorDomain Code=0 \"An unknown error occurred\" UserInfo={NSLocalizedDescription=An unknown error occurred, NSUnderlyingError=0x282b4a670 {Error Domain=ASDErrorDomain Code=500 \"Unhandled exception\" UserInfo={NSUnderlyingError=0x282b4bcf0 {Error Domain=AMSErrorDomain Code=203 \"Bag Load Failed\" UserInfo={NSLocalizedFailureReason=Unable to retrieve p2-product-offers-batch-limit because we failed to load the bag., NSLocalizedDescription=Bag Load Failed, NSUnderlyingError=0x282b4b510 {Error Domain=AMSErrorDomain Code=203 \"Bag Load Failed\" UserInfo=0x283049b40 (not displayed)}}}, NSLocalizedFailureReason=An unknown error occurred, NSLocalizedDescription=Unhandled exception}}},https://ask.dcloud.net.cn/article/282","errCode":0,"errMsg":"Payment_appleiap:Error Domain=SKErrorDomain Code=0 \"An unknown error occurred\" UserInfo={NSLocalizedDescription=An unknown error occurred, NSUnderlyingError=0x282b4a670 {Error Domain=ASDErrorDomain Code=500 \"Unhandled exception\" UserInfo={NSUnderlyingError=0x282b4bcf0 {Error Domain=AMSErrorDomain Code=203 \"Bag Load Failed\" UserInfo={NSLocalizedFailureReason=Unable to retrieve p2-product-offers-batch-limit because we failed to load the bag., NSLocalizedDescription=Bag Load Failed, NSUnderlyingError=0x282b4b510 {Error Domain=AMSErrorDomain Code=203 \"Bag Load Failed\" UserInfo=0x283049b40 (not displayed)}}}, NSLocalizedFailureReason=An unknown error occurred, NSLocalizedDescription=Unhandled exception}}}
06-03
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值