Commit 453ebbfd authored by Han Ruisong's avatar Han Ruisong
Browse files

升级到 4.2.1

1.支持视频后台上传。
2.优化下载流程。
parent 280878c3
This diff is collapsed.
......@@ -222,9 +222,9 @@
}
}
-(void)backgroundSessionCompletion
-(void)downloadBackgroundSessionCompletion
{
NSLog(@"DWDownloadManagerViewController backgroundSessionCompletion");
NSLog(@"DWDownloadManagerViewController downloadBackgroundSessionCompletion");
}
#pragma mark - delegate
......
......@@ -92,8 +92,8 @@
-(void)reloadLoaclData
{
//请自行替换数据
NSArray * videos = @[@""];
NSArray * videos = @[];
for (int i = 0; i < videos.count; i++) {
DWVodModel * vodModel = [[DWVodModel alloc]init];
vodModel.videoId = [videos objectAtIndex:i];
......
This diff is collapsed.
//
// DWUploadModel.h
// Demo
//
// Created by luyang on 2018/3/26.
// Copyright © 2018年 com.bokecc.www. All rights reserved.
//
#import <Foundation/Foundation.h>
typedef NS_ENUM(NSUInteger,DWUploadStatus) {
DWUploadStatusUploading =0,
DWUploadStatusPause,
DWUploadStatusFail,
DWUploadStatusFinish
};
@interface DWUploadModel : NSObject
@property (nonatomic,copy)NSString *first;//是否是第一次上传
@property (copy, nonatomic)NSString *videoPath;
@property (copy, nonatomic)NSString *userID;
@property (copy, nonatomic)NSString *apiKey;
@property (copy, nonatomic)NSString *videoTitle;
@property (copy, nonatomic)NSString *videoTag;
@property (copy, nonatomic)NSString *videoDescripton;
@property (assign, nonatomic)CGFloat videoUploadProgress;
@property (assign, nonatomic)CGFloat videoFileSize;
@property (assign, nonatomic)CGFloat videoUploadedSize;
@property (copy, nonatomic)NSDictionary *uploadContext;
@property (assign,nonatomic)DWUploadStatus status;
@end
//
// DWUploadModel.m
// Demo
//
// Created by luyang on 2018/3/26.
// Copyright © 2018年 com.bokecc.www. All rights reserved.
//
#import "DWUploadModel.h"
@implementation DWUploadModel
@end
#import <UIKit/UIKit.h>
#import "DWUploadModel.h"
@interface DWUploadTableViewCell : UITableViewCell
@property(nonatomic,strong)UIImageView * thumbnailView;
......@@ -10,10 +9,8 @@
@property(nonatomic,strong)UILabel * stateLabel;
@property(nonatomic,strong)UILabel * scheduleLabel;
@property(nonatomic,strong)DWUploader * uploader;
@property(nonatomic,strong)DWUploadModel * uploadModel;
-(void)updateCell;
-(void)updateCellTotalBytesSent:(int64_t)totalBytesSent WithExpectedToSend:(int64_t)expectedToSend;
@end
......@@ -83,58 +83,48 @@
{
_uploadModel = uploadModel;
//拼接路径
NSString *tmp =NSTemporaryDirectory();
uploadModel.videoPath =[tmp stringByAppendingPathComponent:[uploadModel.videoPath lastPathComponent]];
if ([[NSFileManager defaultManager] fileExistsAtPath:uploadModel.videoPath]) {
// 视频缩略图
UIImage *image = [DWTools getThumbnailImage:uploadModel.videoPath time:1];
[self.thumbnailView setImage:image];
if ([uploadModel.otherInfo objectForKey:@"image"]) {
self.thumbnailView.image = [UIImage imageWithData:[uploadModel.otherInfo objectForKey:@"image"]];
}else{
self.thumbnailView.image = [UIImage imageNamed:@"icon_placeholder.png"];
}
[self updateCell];
}
-(void)updateCell
{
// 视频标题
self.titleLabel.text = self.uploadModel.videoTitle;
self.titleLabel.text = self.uploadModel.title;
CGFloat titleLabelWidth = (ScreenWidth - 10 - 128 - 10 - 10);
CGSize size = [DWTools widthWithHeight:titleLabelWidth andFont:self.titleLabel.font andLabelText:self.titleLabel.text];
if (ceil(size.height) < (self.titleLabel.font.lineHeight * 2)) {
[_titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.thumbnailView).offset(5);
make.height.equalTo(@14);
make.height.equalTo(@16);
}];
}else{
[_titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.thumbnailView);
make.height.equalTo(@36);
make.height.equalTo(@40);
}];
}
self.progressView.progress = self.uploadModel.videoUploadProgress;
if (self.uploadModel.status == DWUploadStatusFinish) {
if (self.uploadModel.state == DWUploadStateFinish) {
self.progressView.hidden = YES;
self.scheduleLabel.hidden = YES;
self.stateLabel.text = [NSString stringWithFormat:@"%.2fM",self.uploadModel.videoFileSize/1024.0/1024.0];
self.stateLabel.text = [NSString stringWithFormat:@"%.2fM",self.uploadModel.fileSize/1024.0/1024.0];
self.progressView.progress = 1;
}else{
//未完成
self.progressView.hidden = NO;
self.scheduleLabel.hidden = NO;
switch (self.uploadModel.status) {
case DWUploadStatusFail:{
switch (self.uploadModel.state) {
case DWUploadStateFail:{
self.stateLabel.text = @"已失败";
break;
}
case DWUploadStatusUploading:{
case DWUploadStateUploading:{
self.stateLabel.text = @"上传中";
break;
}
case DWUploadStatusPause:{
case DWUploadStatePause:{
self.stateLabel.text = @"已暂停";
break;
}
......@@ -142,10 +132,17 @@
break;
}
float uploadedSizeMB = [self.uploadModel videoUploadedSize]/1024.0/1024.0;
float fileSizeMB = [self.uploadModel videoFileSize]/1024.0/1024.0;
self.scheduleLabel.text = [NSString stringWithFormat:@"%0.1fM/%0.1fM", uploadedSizeMB, fileSizeMB];
[self updateCellTotalBytesSent:self.uploadModel.totalSentBytes WithExpectedToSend:self.uploadModel.fileSize];
}
}
-(void)updateCellTotalBytesSent:(int64_t)totalBytesSent WithExpectedToSend:(int64_t)expectedToSend
{
float uploadedSizeMB = self.uploadModel.totalSentBytes/1024.0/1024.0;
float fileSizeMB = self.uploadModel.fileSize/1024.0/1024.0;
self.scheduleLabel.text = [NSString stringWithFormat:@"%0.1fM/%0.1fM", uploadedSizeMB, fileSizeMB];
self.progressView.progress = uploadedSizeMB / fileSizeMB;
}
@end
......@@ -143,8 +143,11 @@
}
-(void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)(void))completionHandler
{
[[DWDownloadSessionManager manager] setBackgroundSessionCompletionHandler:completionHandler];
{
//下载的应该也得 搞个id传进去
[[DWDownloadSessionManager manager] setBackgroundSession:identifier CompletionHandler:completionHandler];
[[DWUploadSessionManager manager] setUploadSession:identifier CompletionHandler:completionHandler];
}
-(UICollectionViewFlowLayout *)getLayout
......
......@@ -21,7 +21,7 @@
- (void)downloadModel:(DWDownloadModel *)downloadModel error:(NSError *)error;
// 后台下载完成时回调
- (void)backgroundSessionCompletion;
- (void)downloadBackgroundSessionCompletion;
@end
......@@ -164,14 +164,13 @@
*/
-(void)reStartDownloadUrlWithNewUrlString:(NSString *)newUrlString AndDownloadModel:(DWDownloadModel *)downloadModel;
/**
获取appdelegate,handleEventsForBackgroundURLSession事件回调
@param identifier identifier
@param completionHandler completionHandler
*/
-(void)setBackgroundSessionCompletionHandler:(void (^)())completionHandler;
-(void)setBackgroundSession:(NSString *)identifier CompletionHandler:(void (^)())completionHandler;
//3.x.x升级4.x.x以上版本所使用的过渡方法
/**
......
......@@ -61,7 +61,8 @@ typedef NS_ENUM(NSUInteger, DWSDK_SERVICE_ERROR) {
ERROR_UPLOAD_NOTPERMISSION = 4005 , //用户服务无权限
ERROR_UPLOAD_FAIL = 4100 , //上传失败
ERROR_UPLOAD_ANALYSIS = 4150 , //上传数据解析失败
ERROR_UPLOAD_RECEIVE = 4301 , //获取上传服务器失败
ERROR_UPLOAD_FILEDAMAGED = 4302 , //上传文件已损坏
};
#endif /* DWErrorCode_h */
#import "DWLog.h"
#import "DWUploader.h"
#import "DWVideoCompressController.h"
#import "DWAdInfo.h"
......@@ -12,6 +11,10 @@
#import "DWDownloadUtility.h"
#import "DWBatchDownloadUtility.h"
//上传相关
#import "DWUploadSessionManager.h"
#import "DWUploadModel.h"
//VR
#import "DWVRLibrary.h"
#import "DWVideoDataAdapter.h"
......@@ -23,5 +26,5 @@
#import "DWVodAdInfoModel.h"
//版本号
#define SDK_VERSION @"4.2.0"
#define SDK_VERSION @"4.2.1"
//
// DWUploadModel.h
// Demo
//
// Created by zwl on 2019/8/5.
// Copyright © 2019 com.bokecc.www. All rights reserved.
//
#import <Foundation/Foundation.h>
@class DWUploadWaterMarkModel;
typedef NS_ENUM(NSUInteger,DWUploadState) {
DWUploadStateNone = 0, //未开始上传
DWUploadStateReadying, //准备中
DWUploadStateUploading, //上传中
DWUploadStatePause, //上传暂停
DWUploadStateFail, //上传失败
DWUploadStateFinish //上传完成
};
@interface DWUploadModel : NSObject
///上传状态
@property(nonatomic,assign,readonly)DWUploadState state;
///视频标题
@property(nonatomic,strong,readonly)NSString * title;
///视频tag
@property(nonatomic,strong,readonly)NSString * tag;
///视频描述信息
@property(nonatomic,strong,readonly)NSString * desc;
///视频分类
@property(nonatomic,strong,readonly)NSString * categoryId;
///上传进度
@property(nonatomic,assign,readonly)CGFloat progress;
///上传文件总字节数
@property(nonatomic,assign,readonly)int64_t fileSize;
///已上传字节数
@property(nonatomic,assign,readonly)int64_t totalSentBytes;
///本次发送字节数
@property(nonatomic,assign,readonly)int64_t sentBytes;
///自定义参数
@property(nonatomic,copy)NSDictionary * otherInfo;
///视频id
@property(nonatomic,strong,readonly)NSString * videoId;
///回调地址
@property(nonatomic,strong,readonly)NSString * notifyURL;
///是否裁剪 @"1"为裁剪 @“0”不裁剪 不设置默认为不裁剪
@property(nonatomic,copy)NSString * isCrop;
@property(nonatomic,copy)NSString * ew;
///账号id
@property(nonatomic,strong,readonly)NSString * userId;
///视频水印
@property(nonatomic,strong,readonly)DWUploadWaterMarkModel * waterMark;
@end
@interface DWUploadWaterMarkModel : NSObject
///水印文字内容, 1-50个字符,数字、字母、汉字,不填写则文字水印不生效
@property(nonatomic,strong,readonly)NSString * text;
///水印位置0,左上 1右上 2左下 3右下,默认3,非必填
@property(nonatomic,strong,readonly)NSNumber * corner;
///X轴偏移像素值,要求大于0,默认值5,超出视频大小按默认值,非必填
@property(nonatomic,strong,readonly)NSNumber * offsetX;
///offsetY Y轴偏移像素值,要求大于0,默认值5,超出视频大小按默认值,非必填
@property(nonatomic,strong,readonly)NSNumber * offsetY;
//字体类型:0,微软雅黑 1宋体 2黑体,默认0,非必填
@property(nonatomic,strong,readonly)NSNumber * fontFamily;
///字体大小,[0-100],默认12
@property(nonatomic,strong,readonly)NSNumber * fontSize;
///16进制字体颜色,如#FFFFFF,不能写#号,默认灰色D3D3D3,非必填
@property(nonatomic,strong,readonly)NSString * fontColor;
///透明度,[0-100],默认100,100为不透明,非必填
@property(nonatomic,strong,readonly)NSNumber * fontAlpha;
@end
//
// DWUploadSessionManager.h
// Demo
//
// Created by zwl on 2019/8/5.
// Copyright © 2019 com.bokecc.www. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "DWUploadModel.h"
@protocol DWUploadSessionManagerDelegate <NSObject>
@optional
//开始上传
-(void)uploadSessionManagerBeginWithUploadModel:(DWUploadModel *)uploadModel;
//更新上传状态
-(void)uploadSessionManagerUploadModel:(DWUploadModel *)uploadModel WithState:(DWUploadState)state;
//更新上传进度
-(void)uploadSessionManagerUploadModel:(DWUploadModel *)uploadModel totalBytesSent:(int64_t)totalBytesSent WithExpectedToSend:(int64_t)expectedToSend;
//上传失败回调
-(void)uploadSessionManagerUploadModel:(DWUploadModel *)uploadModel WithError:(NSError *)error;
//后台任务完成时回调
-(void)uploadBackgroundSessionCompletion;
@end
@interface DWUploadSessionManager : NSObject
/**
上传数据列表
*/
@property(nonatomic,strong,readonly)NSArray <DWUploadModel *> * uploadModelList;
/**
代理
*/
@property(nonatomic,weak) id <DWUploadSessionManagerDelegate> delegate;
/**
初始化DWUploadSessionManager
@return DWUploadSessionManager对象
*/
+(DWUploadSessionManager *)manager;
/**
初始化上传对象
@param userId 用户ID,不能为nil
@param apikey 用户秘钥,不能为nil
@param title 视频标题,不能为nil
@param description 视频描述
@param tag 视频标签
@param path 视频路径,不能为nil
@param notifyURL 通知URL
@return 上传对象model
*/
+(DWUploadModel *)createUploadModelWithUserId:(NSString *)userId
Apikey:(NSString *)apikey
VideoTitle:(NSString *)title
VideoDescription:(NSString *)description
VideoTag:(NSString *)tag
VideoPath:(NSString *)videoPath
CategoryId:(NSString *)categoryId
NotifyURL:(NSString *)notifyURL;
/**
添加视频水印,请在调用startWithUploadModel:方法前设置,否则不生效。
@param uploadModel DWUploadModel对象
@param text 水印文字内容, 1-50个字符,数字、字母、汉字,不填写则文字水印不生效
@param corner 水印位置0,左上 1右上 2左下 3右下,默认3,非必填
@param offsetX X轴偏移像素值,要求大于0,默认值5,超出视频大小按默认值,非必填
@param offsetY Y轴偏移像素值,要求大于0,默认值5,超出视频大小按默认值,非必填
@param fontFamily 字体类型:0,微软雅黑 1宋体 2黑体,默认0,非必填
@param fontSize 字体大小,[0-100],默认12
@param fontColor 16进制字体颜色,如#FFFFFF,不能写#号,默认灰色D3D3D3,非必填
@param fontAlpha 透明度,[0-100],默认100,100为不透明,非必填
@return 是否设置成功。YES 设置成功,NO 设置失败,参数不合法
*/
-(BOOL)insertWaterMarkWithUploadModel:(DWUploadModel *)uploadModel
Text:(NSString *)text
Corner:(NSNumber *)corner
OffsetX:(NSNumber *)offsetX
OffsetY:(NSNumber *)offsetY
FontFamily:(NSNumber *)fontFamily
FontSize:(NSNumber *)fontSize
FontColor:(NSString *)fontColor
FontAlpha:(NSNumber *)fontAlpha;
/**
保存视频文件,以供上传使用
@param videoPath 视频文件路径
@return 本地文件路径
*/
-(NSString *)moveToLocalWithVideoPath:(NSString *)videoPath;
/**
开始上传任务
@param uploadModel DWUploadModel对象
*/
-(void)startWithUploadModel:(DWUploadModel *)uploadModel;
/**
暂停上传任务
@param uploadModel DWUploadModel对象
*/
-(void)suspendWithUploadModel:(DWUploadModel *)uploadModel;
/**
继续上传任务
@param uploadModel DWUploadModel对象
*/
-(void)resumeWithUploadModel:(DWUploadModel *)uploadModel;
/**
删除上传任务
@param uploadModel DWUploadModel对象
*/
-(void)deleteWithUploadModel:(DWUploadModel *)uploadModel;
/**
获取appdelegate,handleEventsForBackgroundURLSession事件回调
@param identifier identifier
@param completionHandler completionHandler
*/
-(void)setUploadSession:(NSString *)identifier CompletionHandler:(void (^)())completionHandler;
@end
#import <Foundation/Foundation.h>
@class DWUploader;
@protocol DWUploaderDelegate <NSObject>
@optional
//checkupload第一次请求成功的回调
- (void)checkUploadWithFilePath:(NSString *)filePath;
@end
/**
上传进度
@param progress 上传进度
@param totalBytesWritten 已上传数据大小
@param totalBytesExpectedToWrite 总数据大小
*/
typedef void (^DWUploaderProgressBlock)(float progress, NSInteger totalBytesWritten, NSInteger totalBytesExpectedToWrite);
/**
视频上传上下文
@param videoContext 保存视频上传上下文。它用来在 filaedBlock 被调用时,使用 initWithVideoContext: 方法重新初始化 uploader,调用 resume 方法继续上传。
*/
typedef void (^DWUploaderVideoContextForRetryBlock)(NSDictionary *videoContext);
/**
上传成功时,被调用。
*/
typedef void (^DWUploaderFinishBlock)();
/**
上传失败时,被调用
@param error 错误
*/
typedef void (^DWErrorBlock)(NSError *error);
@interface DWUploader : NSObject
/**
上传过程中HTTP通信请求超时时间
*/
@property (assign, nonatomic)NSTimeInterval timeoutSeconds;
/**
在该block获取上传进度,可以在block内更新UI,如更新上传进度条。
*/
@property (copy, nonatomic)DWUploaderProgressBlock progressBlock;
/**
上传完成时回调该block,可以在block内更新UI,如将视频标记为上传完成。
*/
@property (copy, nonatomic)DWUploaderFinishBlock finishBlock;
/**
上传失败时回调该block,可以在该block内更新UI,如将视频标记为上传失败。
*/
@property (copy, nonatomic)DWErrorBlock failBlock;
/**
在该block内获取上传上下文,并保存上传上下文,用来实现断线续传。
*/
@property (copy, nonatomic)DWUploaderVideoContextForRetryBlock videoContextForRetryBlock;
/**
当遇到网络问题或服务器原因时上传暂停,回调该block。
*/
@property (copy, nonatomic)DWErrorBlock pausedBlock;
/**
代理
*/