ios 阿里云oss视频下载失败

原因:返回的视频url经过url编码已经含有%,无需在经过url转码

https://xxxx.oss-cn-xxx.aliyuncs.com/video/%E9%A5%BF%E4%BA%86%E9%A5%BF%E4%BA%86.mp4

stringByAddingPercentEscapesUsingEncoding不用写.

 

-(void)clickDownLoad{
    
    NSLog(@"clickDownLoad videoUrl :%@",_movie.videoUrl);
    
    if (_movie.videoUrl) {
    }else{
        [RemindView showHUDWithText:@"下载地址错误" delay:1 onView:KeyWindow];
        return;
    }
    
    [self showHud];
    NSString *urlstr = [NSString stringWithFormat:@"%@",_movie.videoUrl];
    
    //https://yxhuda.oss-cn-shenzhen.aliyuncs.com/video/%E9%A5%BF%E4%BA%86%E9%A5%BF%E4%BA%86.mp4
    //这样的特殊字符无法播放或者下载,先url转码
//    urlstr = [urlstr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    
    NSLog(@"clickDownLoad newurl :%@",urlstr);
    
//    urlstr = [urlstr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    NSLog(@"clickDownLoad newUtf8Url :%@",urlstr);
    
    NSURL *url = [NSURL URLWithString:urlstr];
    
    NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
    NSString *dateStr = [[ZYPHelper  shareHelper] dateToString:[NSDate date] withDateFormat:@"YYYYMMDDHHmmSS"];
    NSString *savePath = [cachePath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.mp4",dateStr]];
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"video/mpeg",@"video/mp4",@"audio/mp3",nil];//可下载@"text/json", @"text/javascript",@"text/html",@"video/mpeg",@"video/mp4",@"audio/mp3"等
    NSString  *fullPath = savePath;//要保存的沙盒路径
    NSURLRequest *request1 = [NSURLRequest requestWithURL:url];//在线路径
    
    
    NSURLSessionDownloadTask *task = [manager downloadTaskWithRequest:request1 progress:^(NSProgress * _Nonnull downloadProgress) {
        NSLog(@"downloadProgress - :%f",downloadProgress.completedUnitCount/downloadProgress.totalUnitCount*0.01);
    }  destination:^NSURL *(NSURL *targetPath,NSURLResponse *response) {
        NSString *path_sandox =NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask, YES)[0];
        NSLog(@"path_sandox:%@",path_sandox);
        NSString *path = [path_sandox stringByAppendingPathComponent:response.suggestedFilename];
        NSLog(@"path:%@",path);
        return [NSURL fileURLWithPath:fullPath];
    } completionHandler:^(NSURLResponse *_Nonnull response, NSURL * _Nullable filePath, NSError * _Nullable error) {
        [self hideHud];
        if(error){
            [RemindView showHUDWithText:@"下载失败" delay:1 onView:KeyWindow];
        }else{
//            [self showHud]; UISaveVideoAtPathToSavedPhotosAlbum(savePath, self, @selector(), (__bridge void *)self);
            UISaveVideoAtPathToSavedPhotosAlbum(savePath, self, @selector(video:didFinishSavingWithError:contextInfo:), nil);
//            [RemindView showHUDWithText:@"下载完成" delay:1 onView:KeyWindow];
            
            
        }
    }];
    [task resume];
    
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值