Ver código fonte

1.上传数量限制两个
2.限制上传片长度为15M

huangxiaodong 7 meses atrás
pai
commit
213b082450

+ 2 - 2
创维盒子/双子星云手机.xcodeproj/project.pbxproj

@@ -6159,7 +6159,7 @@
 				CODE_SIGN_IDENTITY = "Apple Development";
 				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
 				CODE_SIGN_STYLE = Manual;
-				CURRENT_PROJECT_VERSION = 16;
+				CURRENT_PROJECT_VERSION = 17;
 				DEVELOPMENT_TEAM = "";
 				"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 6SV76WTUUR;
 				FRAMEWORK_SEARCH_PATHS = (
@@ -6241,7 +6241,7 @@
 				CODE_SIGN_IDENTITY = "Apple Development";
 				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
 				CODE_SIGN_STYLE = Manual;
-				CURRENT_PROJECT_VERSION = 16;
+				CURRENT_PROJECT_VERSION = 17;
 				DEVELOPMENT_TEAM = "";
 				"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 6SV76WTUUR;
 				FRAMEWORK_SEARCH_PATHS = (

+ 1 - 1
创维盒子/双子星云手机/AppDelegate/PrefixHeader.pch

@@ -131,7 +131,7 @@ isBangsScreen; \
 #define EachPieceSzie (2*1024*1024) //每片上传文件大小切割
 #define cutVideoPieceSzie (3 * EachPieceSzie) //视频每次切片多少(切完上传再切一次)
 //正在使用
-#define MaxNasUploadPieceSzie (50*1024*1024) //frp上传 限制每片最大xx M
+#define MaxNasUploadPieceSzie (15*1024*1024) //frp上传 限制每片最大xx M
 #define keyToForgetPwd @"%==%"
 #define pageSizeNum 5//500 //分页数量大小
 

+ 1 - 1
创维盒子/双子星云手机/Class/Set/uploadFile/uploadFileManager/boxDownloadFileManager.m

@@ -42,7 +42,7 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
 {
     //[mixDownloadManager shareManager].uid = ksharedAppDelegate.DeviceThirdIdMod.data.sn;
     [customDownloadManager shareManager].uid = ksharedAppDelegate.DeviceThirdIdMod.data.sn;
-    [customDownloadManager shareManager].maxDownLoadCount = 3;
+    [customDownloadManager shareManager].maxDownLoadCount = 2;
     
     [self delItemInDoneTaskFun];
 }

+ 5 - 0
创维盒子/双子星云手机/NAS/nasUploadManager/customUploadOperation.h

@@ -18,6 +18,8 @@ NS_ASSUME_NONNULL_BEGIN
 @interface customUploadOperation : NSObject
 
 @property(nonatomic,strong) uploadFileDataModel *fileModel;
+@property(nonatomic,copy) NSString *filePath;
+@property(nonatomic,strong)NSFileHandle *fileHandle;
 
 /** 上传任务 */
 @property (nonatomic,strong,nullable)NSURLSession *session;
@@ -34,6 +36,9 @@ NS_ASSUME_NONNULL_BEGIN
 /** 下载中上次通知的时间  用来控制通知时间的频率 目前定位一秒 */
 @property (nonatomic, assign) NSTimeInterval  preNotTimeInterval;
 
+-(NSData*)cutVideoFileFunAtIndex:(NSUInteger)dataIndex withMaxLenght:(NSInteger)maxLengt;
+- (void)closeFileHandleFun;
+
 @end
 
 NS_ASSUME_NONNULL_END

+ 77 - 0
创维盒子/双子星云手机/NAS/nasUploadManager/customUploadOperation.m

@@ -12,5 +12,82 @@
 
 @implementation customUploadOperation
 
+#pragma mark 分段读视频文件
+-(NSData*)cutVideoFileFunAtIndex:(NSUInteger)dataIndex withMaxLenght:(NSInteger)maxLengt{
+    HLog(@"视频切片开始 线程:%@",[NSThread currentThread]);
+    uploadFileDataModel *dataModel = _fileModel;
+    NSString *filePath =  _filePath;
+    if(!filePath || filePath.length == 0){
+        filePath = [cachesFileManager getFilePathWithName:dataModel.filename type:uploadFileTypeVideo]; // 文件路径
+    }
 
+    NSFileManager *manager0 =  [NSFileManager defaultManager];;
+    
+    if(![manager0 fileExistsAtPath:filePath]) {
+        return [NSData new];
+    }
+    
+    NSFileHandle *fileHandle = _fileHandle;
+    if(!fileHandle){
+        fileHandle = [NSFileHandle fileHandleForReadingAtPath:filePath]; // 创建文件句柄
+        _fileHandle = fileHandle;
+    }
+    
+      
+    // 设置分段读取的大小,这里以每次读取1KB为例
+    const NSUInteger chunkSize = maxLengt;//cutVideoPieceSzie;//5 * 1024 *1024;
+    NSMutableData *data = [NSMutableData data];
+    
+    if (fileHandle) {
+       
+        long long endOfFile = [fileHandle seekToEndOfFile];
+        
+        if(dataModel.totalBytes == 0
+           || dataModel.totalBytes < endOfFile){//异常处理
+            dataModel.totalBytes = endOfFile;
+        }
+        
+        //异常处理
+        if(endOfFile == dataIndex){
+            dataModel.totalBytes = endOfFile;
+            dataModel.didUploadBytes = endOfFile;
+            dataModel.curUploadStateType = uploadStateDone;
+            [fileHandle closeFile];
+            _fileHandle = nil;
+            return  data;
+        }
+        
+        if (endOfFile >=  chunkSize) {
+            
+            // 读取文件的分段数据到某个位置
+            [fileHandle seekToFileOffset:dataIndex];
+            
+            // 读取文件的分段数据
+            NSData* chunk = [fileHandle readDataOfLength:chunkSize];
+            if (chunk) {
+                [data appendData:chunk];
+            }
+        }
+        else{
+            // 读取文件的分段数据到某个位置
+            [fileHandle seekToFileOffset:dataIndex];
+            
+            [data appendData:[fileHandle readDataToEndOfFile]];
+            // 关闭文件句柄
+            [fileHandle closeFile];
+            _fileHandle = nil;
+        }
+    }
+    
+    HLog(@"视频切片完成 dataIndex:%ld --长度:%ld",dataIndex,[data length])
+    return data;
+}
+
+- (void)closeFileHandleFun
+{
+    if(_fileHandle){
+        [_fileHandle closeFile];
+        _fileHandle = nil;
+    }
+}
 @end

+ 17 - 3
创维盒子/双子星云手机/NAS/nasUploadManager/nasMixUploadManager.m

@@ -35,7 +35,7 @@
 - (instancetype)init {
 
     if (self = [super init]) {
-        _maxUploadLoadCount = 3;
+        _maxUploadLoadCount = 2;
         
         _arrayLock = [NSLock new];
         //[self registeNotification];
@@ -107,6 +107,9 @@
     if(operation){
         HLog(@"删除完成的上传任务")
         [_arrayLock lock];
+        if(operation.fileHandle){
+            [operation closeFileHandleFun];
+        }
         [self.uploadingOperationArr removeObject:operation];
         [_arrayLock unlock];
     }
@@ -438,7 +441,7 @@
     [paraDict setObject:[NSNumber numberWithLong:position] forKey:@"position"];
     
     //视频数据切片
-    __block NSData *videoData = [self cutVideoFileFunAtIndex:position withMaxLenght:MaxNasUploadPieceSzie withModel:operation.fileModel];
+    __block NSData *videoData = [self cutVideoFileFunAtIndex:position withMaxLenght:MaxNasUploadPieceSzie withModel:operation.fileModel withOperation:operation];
     
     if(!videoData ||videoData.length ==0){
         HLog(@"视频没获取到")
@@ -475,7 +478,10 @@
 }
 
 #pragma mark 分段读视频文件
--(NSData*)cutVideoFileFunAtIndex:(NSUInteger)dataIndex withMaxLenght:(NSInteger)maxLengt withModel:(uploadFileDataModel*)dataModel{
+-(NSData*)cutVideoFileFunAtIndex:(NSUInteger)dataIndex withMaxLenght:(NSInteger)maxLengt withModel:(uploadFileDataModel*)dataModel withOperation:(customUploadOperation*)operation{
+    
+    //return [operation cutVideoFileFunAtIndex:dataIndex withMaxLenght:maxLengt];
+    
     HLog(@"视频切片开始 线程:%@",[NSThread currentThread]);
     
     NSString *filePath = [cachesFileManager getFilePathWithName:dataModel.filename type:uploadFileTypeVideo]; // 文件路径
@@ -865,6 +871,11 @@ didReceiveResponse:(NSURLResponse *)response
         if([operation.fileModel.filename isEqualToString:fileModel.filename]){
             operation.isCancelType = YES;
             [operation.dataTask cancel];
+            
+            if(operation.fileHandle){
+                [operation closeFileHandleFun];
+            }
+            
             didUnLockType = YES;
             [_arrayLock unlock];
             [self beginUploadAfterDeleteOperationBy:operation];
@@ -898,6 +909,9 @@ didReceiveResponse:(NSURLResponse *)response
         HLog(@"正在遍历数组 _uploadingOperationArr:%@",_uploadingOperationArr);
         operation.isCancelType = YES;
         [operation.dataTask cancel];
+        if(operation.fileHandle){
+            [operation closeFileHandleFun];
+        }
     }
     
     [_uploadingOperationArr removeAllObjects];