Bladeren bron

1.验证下载视频流程完成

huangxiaodong 1 jaar geleden
bovenliggende
commit
4be9addfe7

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

@@ -139,8 +139,10 @@ isBangsScreen; \
 
 #pragma mark - 云盘文件缓存路径
 /**云盘文件下载-文件缓存路径*/
-#define kPath_YunPan_Download_Folder  stringKeyAddSn(@"download")
+#define kPath_YunPan_Download_Folder  [HWDataManager cachesPathForAccount:[connectDeviceManager shareInstance].DeviceThirdIdMod.data.sn fileFolder:@"download"]
+
 /**云盘文件上传-文件缓存路径*/
-#define kPath_YunPan_Upload_Folder    stringKeyAddSn(@"upload")
+#define kPath_YunPan_Upload_Folder    [HWDataManager cachesPathForAccount:[connectDeviceManager shareInstance].DeviceThirdIdMod.data.sn fileFolder:@"Upload"]
+
 
 #endif /* PrefixHeader_pch */

+ 8 - 1
创维盒子/双子星云手机/AppDelegate/SceneDelegate.m

@@ -444,7 +444,7 @@
         NSString *curStr = context.URL.absoluteString;
         if([curStr rangeOfString:@"openprivacyxapp://page"].location != NSNotFound){
             _getShareStr = curStr;
-            [self shareAwakenAppBy:curStr];
+            [self delayedHandlShareAwakenAppBy:curStr];
             break;
         }
         
@@ -453,6 +453,13 @@
     }
 }
 
+- (void)delayedHandlShareAwakenAppBy:(NSString*)curStr{
+    
+    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+        [self shareAwakenAppBy:curStr];
+    });
+    
+}
 
 
 #pragma mark 初始化数据库-DB_BrowserWindows_TableName

+ 13 - 3
创维盒子/双子星云手机/Class/Set/previewFile/model/ShareRecordModel.h

@@ -20,7 +20,7 @@ typedef enum{
 
 typedef enum{
     downloadBoxStateBegin = 0,
-    downloadBoxStateUploading,//占位 未用到
+    downloadBoxStateDownloadloading,//占位 未用到
     downloadBoxStateSuspend,//占位 未用到
     downloadBoxStateDone,
     downloadBoxStateFail,
@@ -35,12 +35,22 @@ typedef enum{
 //@property (nonatomic, assign) long  size;
 //id
 
-//自定义
+//自定义 保存
 @property (nonatomic, assign) shareSaveBoxStateType saveboxStateType;
 @property (nonatomic, copy) NSString*boxSavePath;//保存路口
 
-//
+//下载
 @property (nonatomic, assign) shareDownloadBoxStateType downloadBoxStateType;
+/** 下载的文件总大小 */
+@property (nonatomic,assign) int64_t totalSize;
+
+/** 当前下载了多少 */
+@property (nonatomic,assign) int64_t currentSize;
+@property (nonatomic, assign)  int64_t preDownloadBytes;//已经上传的字节数
+
+@property (nonatomic, assign) NSTimeInterval  preTimeInterval;//计算速度用
+@property (nonatomic, assign) NSTimeInterval  curTimeInterval;//计算速度用
+
 @end
 
 @protocol ShareFileDataModel;

+ 120 - 116
创维盒子/双子星云手机/Class/Set/uploadFile/receiveView/boxDownloadFileRecordCell.m

@@ -193,7 +193,7 @@
         self.selectButton.hidden = YES;
         
         if(_curShareFileDataModel.downloadBoxStateType == downloadBoxStateBegin
-           ||_curShareFileDataModel.downloadBoxStateType == downloadBoxStateUploading
+           ||_curShareFileDataModel.downloadBoxStateType == downloadBoxStateDownloadloading
            ||_curShareFileDataModel.downloadBoxStateType == downloadBoxStateSuspend){
             _upLoadStateButton.hidden = NO;
         }
@@ -308,120 +308,124 @@
     
     //HLog(@"1111111: %@ %@",curShareFileDataModel.fileUrl,curShareFileDataModel.fileSize);
 
-//    //进度设置
-//    CGRect frame = CGRectMake(0, 0, SCREEN_W - 15*2 - 34*2, 2);
-//    
-//    NSInteger totalSize = curCouldPhoneFileModel.length;
-//    if(totalSize == 0.0){
-//        totalSize += 0.0001;
-//    }
-//    
-//    CGFloat curProgress = curCouldPhoneFileModel.didDownloadBytes/(totalSize*1.0);
-//    
-//    if(curProgress > 1){
-//        curProgress = 1;
-//    }
-//    
-//    frame.size.width =  frame.size.width * curProgress;
-//    
-//    if (isnan(frame.size.width))
-//    {
-//        HLog(@"计算出错了");
-//        frame.size.width = 10.0;
-//    }
-//    
-////    HLog(@"%f, %f, %f, %f,",frame.origin.x,frame.origin.y,frame.size.width,frame.size.height);
-////    HLog(@"%@",_progressSelectView);
-//    
-//    _progressSelectView.frame = frame;
-//    //_glayer.frame = frame;
-//    
-//    NSString * totalSizeStr = nil;
-//    NSInteger totalSize_k = totalSize / 1024;
-//    if(totalSize_k < 1024){
-//        totalSizeStr = [[NSString alloc] initWithFormat:@"%ldKB",totalSize_k];
-//    }
-//    else if( totalSize_k >= 1024 && totalSize_k < 1024*1024){
-//        totalSizeStr = [[NSString alloc] initWithFormat:@"%.1fMB",totalSize_k/1024.0];
-//        
-//    }
-//    else{
-//        totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fG",totalSize_k/1024.0/1024.0];
-//    }
-//    
-//    NSString * didUploadStr = nil;
-//    NSInteger didUploadSize_k = curCouldPhoneFileModel.didDownloadBytes / 1024;
-//    if(didUploadSize_k < 1024){
-//        didUploadStr = [[NSString alloc] initWithFormat:@"%ldKB",didUploadSize_k];
-//    }
-//    else if( didUploadSize_k >= 1024 && didUploadSize_k < 1024*1024){
-//        didUploadStr = [[NSString alloc] initWithFormat:@"%.1fMB",didUploadSize_k/1024.0];
-//        
-//    }
-//    else{
-//        didUploadStr = [[NSString alloc] initWithFormat:@"%.2fG",didUploadSize_k/1024.0/1024.0];
-//    }
-//    
-//    if(curCouldPhoneFileModel.curDownloadStateType == downloadStateWait){
-//        [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_wait"] forState:UIControlStateNormal];
-//    }
-//    else if(curCouldPhoneFileModel.curDownloadStateType == downloadStateUploading){
-//        [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_suspend"] forState:UIControlStateNormal];
-//        _fileSpeedlabel.hidden = NO;
-//        
-//        //
-//        _fileSpeedlabel.text = @"";
-//        
-//        if(curCouldPhoneFileModel.preTimeInterval <= 0){
-//            _fileSpeedlabel.text = @"--";
-//        }
-//        else{
-//            NSTimeInterval  timers = curCouldPhoneFileModel.curTimeInterval - curCouldPhoneFileModel.preTimeInterval;
-//            
-//            if(timers > 0){
-//                //long speed= 1*1024*1024 / timers;
-//                
-//                long speed= (curCouldPhoneFileModel.didDownloadBytes - curCouldPhoneFileModel.preDownloadBytes) / timers;
-//                
-//                NSString * speedStr = nil;
-//                NSInteger speed_k = speed / (1024);
-//                if(speed_k < 1024){
-//                    speedStr = [[NSString alloc] initWithFormat:@"%ldKB/s",speed_k];
-//                }
-//                else {
-//                    speedStr = [[NSString alloc] initWithFormat:@"%.1fMB/s",speed_k/1024.0];
-//                }
-//                
-//                _fileSpeedlabel.text = speedStr;
-//            }
-//        }
-//        
-//        curCouldPhoneFileModel.preTimeInterval = curCouldPhoneFileModel.curTimeInterval;
-//        curCouldPhoneFileModel.preDownloadBytes = curCouldPhoneFileModel.didDownloadBytes;
-//    }
-//    else if(curCouldPhoneFileModel.curDownloadStateType == downloadStateSuspend){
-//        [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_start"] forState:UIControlStateNormal];
-//    }
-//    else if(curCouldPhoneFileModel.curDownloadStateType == downloadStateFail){
-//        [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_reStart"] forState:UIControlStateNormal];
-//        _progressBgView.hidden = YES;
-//    }
-//    else{
-//        _upLoadStateButton.hidden = YES;
-//        _progressBgView.hidden = YES;
-//    }
-//    
-//    
-//    if(curCouldPhoneFileModel.curDownloadStateType == downloadStateDone){
-//        NSString*tipStr = NSLocalizedString(@"File_download_Path_default_done",nil);
-//        _fileProgresslabel.text = [[NSString alloc] initWithFormat:@"%@  %@",totalSizeStr,tipStr];
-//    }
-//    else if(curCouldPhoneFileModel.curDownloadStateType == downloadStateFail){
-//        _fileProgresslabel.text = [[NSString alloc] initWithFormat:@"%@",totalSizeStr];
-//    }
-//    else{
-//        _fileProgresslabel.text = [[NSString alloc] initWithFormat:@"%@/%@",didUploadStr,totalSizeStr];
-//    }
+    //进度设置
+    CGRect frame = CGRectMake(0, 0, SCREEN_W - 15*2 - 34*2, 2);
+    
+    if(curShareFileDataModel.totalSize == 0){
+        curShareFileDataModel.totalSize = curShareFileDataModel.fileSize.longLongValue;
+    }
+    
+    NSInteger totalSize = curShareFileDataModel.totalSize;
+    if(totalSize == 0.0){
+        totalSize += 0.0001;
+    }
+    
+    CGFloat curProgress = curShareFileDataModel.currentSize/(totalSize*1.0);
+    
+    if(curProgress > 1){
+        curProgress = 1;
+    }
+    
+    frame.size.width =  frame.size.width * curProgress;
+    
+    if (isnan(frame.size.width))
+    {
+        HLog(@"计算出错了");
+        frame.size.width = 10.0;
+    }
+    
+//    HLog(@"%f, %f, %f, %f,",frame.origin.x,frame.origin.y,frame.size.width,frame.size.height);
+//    HLog(@"%@",_progressSelectView);
+    
+    _progressSelectView.frame = frame;
+    //_glayer.frame = frame;
+    
+    NSString * totalSizeStr = nil;
+    NSInteger totalSize_k = totalSize / 1024;
+    if(totalSize_k < 1024){
+        totalSizeStr = [[NSString alloc] initWithFormat:@"%ldKB",totalSize_k];
+    }
+    else if( totalSize_k >= 1024 && totalSize_k < 1024*1024){
+        totalSizeStr = [[NSString alloc] initWithFormat:@"%.1fMB",totalSize_k/1024.0];
+        
+    }
+    else{
+        totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fG",totalSize_k/1024.0/1024.0];
+    }
+    
+    NSString * didUploadStr = nil;
+    NSInteger didUploadSize_k = curShareFileDataModel.currentSize / 1024;
+    if(didUploadSize_k < 1024){
+        didUploadStr = [[NSString alloc] initWithFormat:@"%ldKB",didUploadSize_k];
+    }
+    else if( didUploadSize_k >= 1024 && didUploadSize_k < 1024*1024){
+        didUploadStr = [[NSString alloc] initWithFormat:@"%.1fMB",didUploadSize_k/1024.0];
+        
+    }
+    else{
+        didUploadStr = [[NSString alloc] initWithFormat:@"%.2fG",didUploadSize_k/1024.0/1024.0];
+    }
+    
+    if(curShareFileDataModel.downloadBoxStateType == downloadBoxStateBegin){
+        [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_wait"] forState:UIControlStateNormal];
+    }
+    else if(curShareFileDataModel.downloadBoxStateType == downloadBoxStateDownloadloading){
+        [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_suspend"] forState:UIControlStateNormal];
+        _fileSpeedlabel.hidden = NO;
+        
+        //
+        _fileSpeedlabel.text = @"";
+        
+        if(curShareFileDataModel.preTimeInterval <= 0){
+            _fileSpeedlabel.text = @"--";
+        }
+        else{
+            NSTimeInterval  timers = curShareFileDataModel.curTimeInterval - curShareFileDataModel.preTimeInterval;
+            
+            if(timers > 0){
+                //long speed= 1*1024*1024 / timers;
+                
+                long speed= (curShareFileDataModel.currentSize - curShareFileDataModel.preDownloadBytes) / timers;
+                
+                NSString * speedStr = nil;
+                NSInteger speed_k = speed / (1024);
+                if(speed_k < 1024){
+                    speedStr = [[NSString alloc] initWithFormat:@"%ldKB/s",speed_k];
+                }
+                else {
+                    speedStr = [[NSString alloc] initWithFormat:@"%.1fMB/s",speed_k/1024.0];
+                }
+                
+                _fileSpeedlabel.text = speedStr;
+            }
+        }
+        
+        curShareFileDataModel.preTimeInterval = curShareFileDataModel.curTimeInterval;
+        curShareFileDataModel.preDownloadBytes = curShareFileDataModel.currentSize;
+    }
+    else if(curShareFileDataModel.downloadBoxStateType == downloadBoxStateSuspend){
+        [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_start"] forState:UIControlStateNormal];
+    }
+    else if(curShareFileDataModel.downloadBoxStateType == downloadBoxStateFail){
+        [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_reStart"] forState:UIControlStateNormal];
+        _progressBgView.hidden = YES;
+    }
+    else{
+        _upLoadStateButton.hidden = YES;
+        _progressBgView.hidden = YES;
+    }
+    
+    
+    if(curShareFileDataModel.downloadBoxStateType == downloadBoxStateDone){
+        NSString*tipStr = NSLocalizedString(@"File_download_Path_default_done",nil);
+        _fileProgresslabel.text = [[NSString alloc] initWithFormat:@"%@  %@",totalSizeStr,tipStr];
+    }
+    else if(curShareFileDataModel.downloadBoxStateType == downloadBoxStateFail){
+        _fileProgresslabel.text = [[NSString alloc] initWithFormat:@"%@",totalSizeStr];
+    }
+    else{
+        _fileProgresslabel.text = [[NSString alloc] initWithFormat:@"%@/%@",didUploadStr,totalSizeStr];
+    }
     
 }
 
@@ -456,7 +460,7 @@
         _didTapPressClick();
     }
     
-    if(_curShareFileDataModel.downloadBoxStateType == downloadBoxStateUploading){
+    if(_curShareFileDataModel.downloadBoxStateType == downloadBoxStateDownloadloading){
         [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_start"] forState:UIControlStateNormal];
         
     }

+ 4 - 1
创维盒子/双子星云手机/Class/Set/uploadFile/receiveView/receiveDownloadRecordTableView.h

@@ -24,10 +24,11 @@ NS_ASSUME_NONNULL_BEGIN
 
 @property (nonatomic,assign) BOOL isEditType;
 @property (nonatomic,assign) BOOL isSelectAllType;
+@property (nonatomic,assign) BOOL reDownLoadAgainType;//
 @property (nonatomic,strong) NSMutableArray *selectModelArr;
 
 @property (nonatomic,copy) void (^didLongPressClick)(void);
-@property (nonatomic,copy) void (^didClickReUploadBlock)(couldPhoneFileModel* model);
+@property (nonatomic,copy) void (^didClickReUploadBlock)(ShareFileDataModel* model);
 
 @property (nonatomic,copy) void (^didClickSectionHeadViewRightButton)(NSInteger section);
 @property (nonatomic,copy) void (^didNeedRefreshGetDatabaseFun)(void);
@@ -36,6 +37,8 @@ NS_ASSUME_NONNULL_BEGIN
 - (void)RefreshAllDataFun;
 #pragma mark 单个点击选中后删除
 - (void)deleteModelOneByOneFun;
+//每次进去重新下载
+- (void)reDownLoadAgainFun;
 @end
 
 NS_ASSUME_NONNULL_END

+ 259 - 3
创维盒子/双子星云手机/Class/Set/uploadFile/receiveView/receiveDownloadRecordTableView.m

@@ -29,6 +29,14 @@
         [self initTableHeaderInSectionFun];
         _selectModelArr = [NSMutableArray new];
         _curDataArr = [NSMutableArray new];
+        
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskExeIng:) name:SGDownloadTaskExeing object:nil];
+
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskExeEnd:) name:SGDownloadTaskExeEnd object:nil];
+
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskExeError:) name:SGDownloadTaskExeError object:nil];
+
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskExeSupend:) name:SGDownloadTaskExeSuspend object:nil];
     }
     return self;
 }
@@ -60,9 +68,9 @@
     
     _outSideDataArr = outSideDataArr;
     
-    _downloadingArr = outSideDataArr[0];
-    _downloadDoneArr = outSideDataArr[1];
-    _downloadfailArr = outSideDataArr[2];
+    _downloadingArr = [NSMutableArray arrayWithArray:outSideDataArr[0]];
+    _downloadDoneArr = [NSMutableArray arrayWithArray:outSideDataArr[1]];
+    _downloadfailArr = [NSMutableArray arrayWithArray:outSideDataArr[2]];
     
     [self RefreshAllDataFun];
 }
@@ -505,5 +513,253 @@
 //    [[downloadManager shareInstance] reDownloadFileFunBy:arr withAll:NO];
     
 }
+
+- (void)downloadTaskExeIng:(NSNotification *)notification
+{
+    SGDownloadOperation *model = notification.userInfo.allValues.firstObject;
+    HLog(@"下载中 %lld",model.currentSize);
+    KWeakSelf
+    mainBlock(^{
+        [weakSelf handldDownloadingDataBy:model];
+    });
+    
+}
+
+- (void)downloadTaskExeSupend:(NSNotification *)notification
+{
+    SGDownloadOperation *model = notification.userInfo.allValues.firstObject;
+
+    //KWeakSelf
+    mainBlock(^{
+        //[weakSelf handldDownloadingDataBy:model];
+    });
+    HLog(@"暂停/下载等待中");
+}
+
+- (void)downloadTaskExeEnd:(NSNotification *)notification
+{
+    SGDownloadOperation *model = notification.userInfo.allValues.firstObject;
+
+    KWeakSelf
+    mainBlock(^{
+        [weakSelf handldDownloadDoneDataBy:model];
+        [weakSelf handldDownloadDoneToSaveBy:model];
+        
+    });
+    HLog(@"下载成功");
+}
+
+- (void)downloadTaskExeError:(NSNotification *)notification
+{
+    SGDownloadOperation *model = notification.userInfo.allValues.firstObject;
+
+    KWeakSelf
+    mainBlock(^{
+        //[weakSelf handldDownloadingDataBy:model];
+    });
+    HLog(@"下载失败");
+}
+
+#pragma mark 第一次进来 检测重新下载
+- (void)reDownLoadAgainFun
+{
+    if(_reDownLoadAgainType){
+        return;
+    }
+    else{
+        _reDownLoadAgainType = YES;
+        [[SGDownloadManager shareManager] startAllDownloadTask];
+    }
+    
+    //重新下载
+//    NSMutableArray *handleDownloadArr = [NSMutableArray new];
+//    for (ShareFileDataModel * curModel in _downloadingArr) {
+//        if(curModel.downloadBoxStateType != downloadBoxStateSuspend)
+//        {
+//            [handleDownloadArr addObject:curModel];
+//        }
+//    }
+//    
+//    if(handleDownloadArr.count >0){
+//        [[boxDownloadFileManager shareInstance] beginDownloadFilesByUrls:handleDownloadArr];
+//    }
+}
+
+#pragma mark 下载中数据回调处理
+- (void)handldDownloadingDataBy:(SGDownloadOperation*)model
+{
+    //解码
+    NSString * urlString = [model.url stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+
+    for (ShareFileDataModel*dataModel in _downloadingArr) {
+        //HLog(@"22222222 %@\n%@",urlString,dataModel.fileUrl);
+        if([urlString isEqualToString:dataModel.fileUrl]){
+            dataModel.downloadBoxStateType = downloadBoxStateDownloadloading;
+            dataModel.totalSize = model.totalSize;
+            dataModel.currentSize = model.currentSize;
+            break;
+        }
+    }
+    
+    [self reloadData];
+}
+
+#pragma mark 下载完成数据回调处理
+- (void)handldDownloadDoneDataBy:(SGDownloadOperation*)model
+{
+    //解码
+    NSString * urlString = [model.url stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+
+    for (ShareFileDataModel*dataModel in _downloadingArr) {
+        //HLog(@"22222222 %@\n%@",urlString,dataModel.fileUrl);
+        if([urlString isEqualToString:dataModel.fileUrl]){
+            dataModel.downloadBoxStateType = downloadBoxStateDone;
+            [_downloadDoneArr insertObject:dataModel atIndex:0];
+            [_downloadingArr removeObject:dataModel];
+            break;
+        }
+    }
+    
+    [self RefreshAllDataFun];
+}
+
+#pragma mark 下载完后处理保持流程
+- (void)handldDownloadDoneToSaveBy:(SGDownloadOperation*)model{
+    //解码
+    NSString * urlString = [model.url stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+    NSArray *nameArr= [urlString componentsSeparatedByString:@"."];
+    NSString * pathStr= model.fullPath;
+    
+    //HLog(@"fileName: %@",curShareFileDataModel.fileName);
+    if (nameArr.count >= 2) {
+        NSString *lastName = nameArr.lastObject;
+        
+        lastName = [lastName lowercaseString];
+        
+        if ([lastName rangeOfString:@"jpg"].location != NSNotFound
+                 ||[lastName rangeOfString:@"jpeg"].location != NSNotFound
+                 ||[lastName rangeOfString:@"png"].location != NSNotFound
+                 ||[lastName rangeOfString:@"gif"].location != NSNotFound
+                 ||[lastName rangeOfString:@"bmp"].location != NSNotFound
+                 ||[lastName rangeOfString:@"svg"].location != NSNotFound
+                 ||[lastName rangeOfString:@"tiff"].location != NSNotFound
+                 ||[lastName rangeOfString:@"heic"].location != NSNotFound
+                 ) {//可以保持到相册
+            
+            
+            UIImage *image = [UIImage imageWithContentsOfFile:pathStr];
+            if(image){
+                [self loadImageFinished:image with:pathStr];
+            }
+                
+        }
+        else if ([lastName rangeOfString:@"mp4"].location != NSNotFound
+                 ||[lastName rangeOfString:@"avi"].location != NSNotFound
+                 ||[lastName rangeOfString:@"flv"].location != NSNotFound
+                 ||[lastName rangeOfString:@"wmv"].location != NSNotFound
+                 ||[lastName rangeOfString:@"wkm"].location != NSNotFound
+                 ||[lastName rangeOfString:@"ts"].location != NSNotFound
+                 ||[lastName rangeOfString:@"mov"].location != NSNotFound
+                 ||[lastName rangeOfString:@"rmvb"].location != NSNotFound
+                 ) {//可以保持到相册
+            [self loadVideoFinishedBy:pathStr];
+            
+        }
+        else{//保存到文件
+            
+        }
+    }
+}
+
+
+- (void)loadImageFinished:(UIImage *)image with:(NSString*)fullPath
+{
+    [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
+         //写入图片到相册
+         PHAssetChangeRequest *req = [PHAssetChangeRequest creationRequestForAssetFromImage:image];
+            
+     } completionHandler:^(BOOL success, NSError * _Nullable error) {
+         //NSLog(@"success = %d, error = %@", success, error);
+         if (success) {
+             HLog(@"已将图片保存至相册");
+             [[NSFileManager defaultManager] removeItemAtPath:fullPath error:nil];
+         } else {
+             HLog(@"未能将图片保存至相册");
+         }
+         
+    }];
+}
+
+- (void)loadVideoFinishedBy:(NSString*)fullPath
+{
+    NSString*pathStr = fullPath;
+    
+    PHPhotoLibrary *photoLibrary = [PHPhotoLibrary sharedPhotoLibrary];
+    [photoLibrary performChanges:^{
+        [PHAssetChangeRequest creationRequestForAssetFromVideoAtFileURL:[NSURL
+    fileURLWithPath:pathStr]];
+    } completionHandler:^(BOOL success, NSError * _Nullable error) {
+        if (success) {
+            HLog(@"已将视频保存至相册");
+            [[NSFileManager defaultManager] removeItemAtPath:pathStr error:nil];
+        } else {
+            HLog(@"未能将视频保存至相册");
+        }
+        
+        
+       
+    }];
+}
+
+////下载音频 文件等
+//- (void)loadOtherDataFinished
+//{
+//    [[downloadManager shareInstance] DownloadFileDoneOneFileFun];
+//    
+//    NSString *fileName = [self.curDownloadFileModel getFileNameFun];
+//    NSString*filePath = [cachesFileManager getFilePathWithName:fileName type:DownLoadFileType];
+//    
+//    if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]){
+//        HLog(@"没有找到文件:%@",fileName);
+//        return;
+//    }
+//    
+//    NSURL * fileURL = [NSURL fileURLWithPath:filePath];
+//    UIDocumentPickerViewController *documentPickerVC = [[UIDocumentPickerViewController alloc] initWithURL:fileURL inMode:UIDocumentPickerModeExportToService];
+//    // 设置代理
+//    documentPickerVC.delegate = self;
+//    // 设置模态弹出方式
+//    documentPickerVC.modalPresentationStyle = UIModalPresentationFormSheet;
+//    [self.navigationController presentViewController:documentPickerVC animated:YES completion:nil];
+//}
+// 
+//
+//#pragma mark - UIDocumentPickerDelegate
+//- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls {
+//    // 获取授权
+//    BOOL fileUrlAuthozied = [urls.firstObject startAccessingSecurityScopedResource];
+//    if (fileUrlAuthozied) {
+//        // 通过文件协调工具来得到新的文件地址,以此得到文件保护功能
+//        NSFileCoordinator *fileCoordinator = [[NSFileCoordinator alloc] init];
+//        NSError *error;
+//        
+//        [fileCoordinator coordinateReadingItemAtURL:urls.firstObject options:0 error:&error byAccessor:^(NSURL *newURL) {
+//            // 读取文件
+//            NSString *fileName = [newURL lastPathComponent];
+//            NSError *error = nil;
+//            //NSData *fileData = [NSData dataWithContentsOfURL:newURL options:NSDataReadingMappedIfSafe error:&error];
+//            if (error) {
+//                // 读取出错
+//            } else {
+//                // 上传
+//                NSLog(@"fileName : %@", fileName);
+//                [cachesFileManager removeItemAtPath:fileName type:DownLoadFileType error:nil];
+//            }
+//        }];
+//        [urls.firstObject stopAccessingSecurityScopedResource];
+//    } else {
+//        // 授权失败
+//    }
+//}
 @end
 

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

@@ -147,7 +147,7 @@
     mainBlock(^{
         //[self refreshUIWithModel:model];
     });
-    HLog(@"下载中 %lld",model.currentSize);
+    //HLog(@"下载中 %lld",model.currentSize);
 }
 
 #pragma mark 获取本地数据库数据
@@ -329,5 +329,6 @@
 - (void)AferGetBoxDownloadDataBy:(NSMutableArray*)arr
 {
     _downloadRecordTableView.outSideDataArr = arr;
+    [_downloadRecordTableView reDownLoadAgainFun];
 }
 @end

+ 4 - 0
创维盒子/双子星云手机/Class/Set/uploadFile/uploadFileManager/boxDownloadFileManager.h

@@ -8,6 +8,7 @@
 #import <Foundation/Foundation.h>
 #import "queryOneShareModel.h"
 #import "uploadFileManager.h"
+#import "SGDownloadManager.h"
 NS_ASSUME_NONNULL_BEGIN
 
 
@@ -30,6 +31,9 @@ NS_ASSUME_NONNULL_BEGIN
 #pragma mark 更新本地数据库记录
 //- (void)updataBoxSaveDataBy:(downStatusModel*)downStatusMod;
 
+#pragma mark 开始下载文件 ShareFileDataModel
+- (void)beginDownloadFilesByUrls:(NSArray *)urlArr;
+
 @end
 
 NS_ASSUME_NONNULL_END

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

@@ -27,6 +27,10 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
     
     if (self) {
         //[self initManager];
+        
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskExeEnd:) name:SGDownloadTaskExeEnd object:nil];
+
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskExeError:) name:SGDownloadTaskExeError object:nil];
     }
     
     return self;
@@ -40,10 +44,13 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
             model.bg_tableName = share_box_download_tableName;
         }
         
+        KWeakSelf
         //[ShareFileDataModel bg_saveOrUpdateArray:arr];
         [ShareFileDataModel bg_saveOrUpdateArrayAsync:arr complete:^(BOOL isSuccess) {
-                    
+            [weakSelf beginDownloadFilesByUrls:arr];
         }];
+        
+        
     }
 }
 
@@ -209,4 +216,80 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
 //    
 //    
 //}
+
+#pragma mark 开始下载文件
+- (void)beginDownloadFilesByUrls:(NSArray *)urlArr{
+    
+    NSMutableArray*arr =  [[SGDownloadManager shareManager] getAllOperation];
+    if(arr && arr.count > 0){
+        HLog(@"有任务正在下载");
+        [[SGDownloadManager shareManager] startAllDownloadTask];
+        return;
+    }
+    
+    for (ShareFileDataModel *fileModel in urlArr) {
+
+        NSString *urlString = fileModel.fileUrl;
+        NSString *requestURLEncodedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+        NSURL *curUrl = [NSURL URLWithString:requestURLEncodedString];
+        // 创建下载任务
+//        [[SGDownloadManager shareManager] downloadWithURL:curUrl
+//                                                 complete:^(NSDictionary *respose, NSError *error) {
+//            HLog(@"%@---%@",respose, error);
+//        }];
+        
+        [[SGDownloadManager shareManager] downloadWithURL:curUrl fileType:1 fileSize:0 complete:^(NSDictionary *respose, NSError *error) {
+            HLog(@"%@---%@",respose, error);
+        }];
+        
+        //测试 每次只跑一个
+        //break;
+    }
+
+}
+
+- (void)downloadTaskExeEnd:(NSNotification *)notification
+{
+    SGDownloadOperation *model = notification.userInfo.allValues.firstObject;
+    [self handldDownloadDoneDataBy:model];
+    [[SGDownloadManager shareManager] cancelDownloadWithUrl:model.url];
+    HLog(@"下载成功");
+}
+
+- (void)downloadTaskExeError:(NSNotification *)notification
+{
+    SGDownloadOperation *model = notification.userInfo.allValues.firstObject;
+
+    HLog(@"下载失败");
+}
+
+#pragma mark 下载完成数据回调处理
+- (void)handldDownloadDoneDataBy:(SGDownloadOperation*)model
+{
+    //解码
+    NSString * urlString = [model.url stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+
+    if(_databaseArr && _databaseArr.count == 3 ){
+        NSMutableArray *ingArr = _databaseArr[0];
+        for (ShareFileDataModel*dataModel in ingArr) {
+            //HLog(@"22222222 %@\n%@",urlString,dataModel.fileUrl);
+            if([urlString isEqualToString:dataModel.fileUrl]){
+                [self handleDatabaseArrByDelete:dataModel];
+                
+                dataModel.downloadBoxStateType = downloadBoxStateDone;
+                
+                NSMutableArray *doneArr = _databaseArr[1];
+                [doneArr insertObject:dataModel atIndex:0];
+                
+                //更新数据库
+                [dataModel bg_saveOrUpdateAsync:^(BOOL isSuccess) {
+                                    
+                }];
+                break;
+            }
+        }
+    }
+
+}
+
 @end

+ 1 - 1
创维盒子/双子星云手机/CloudPlayer/View/PlayerView.m

@@ -71,7 +71,7 @@ ShowImageViewDelegate>{
                   inRect:CGRectMake(0, 0, glkshowImageView.drawableWidth, glkshowImageView.drawableHeight)
                 fromRect:[ciImage extent]];
     
-    [self->glkshowImageView display];
+    //[self->glkshowImageView display];
 }
 
 - (void)showIMage

+ 13 - 0
创维盒子/双子星云手机/Helpers/HWDataManager.h

@@ -87,6 +87,19 @@ NS_ASSUME_NONNULL_BEGIN
  */
 + (NSString *)pathForDevicePhotoWithAccount:(NSString *)account deviceId:(NSString *)deviceId;
 
+#pragma mark FileManager - File
+/**
+ * 文件路径:DocumentPath/account/fileFolder
+ * account 路径不需要拼接账号时 传@""
+ */
++ (NSString *)documentPathForAccount:(NSString *)account fileFolder:(NSString *)fileFolder;
+
+/**
+ * 文件路径:CachesPath/account/fileFolder
+ * account 路径不需要拼接账号时 传@""
+ */
++ (NSString *)cachesPathForAccount:(NSString *)account fileFolder:(NSString *)fileFolder;
+
 @end
 
 NS_ASSUME_NONNULL_END

+ 26 - 0
创维盒子/双子星云手机/Helpers/HWDataManager.m

@@ -173,6 +173,32 @@ static HWDataManager *shareInstance = nil;
     return [path stringByAppendingPathComponent:fileFolder];
 }
 
+/**
+ * 文件路径:CachesPath/account/fileFolder
+ * account 路径不需要拼接账号时 传@""
+ */
++ (NSString *)cachesPathForAccount:(NSString *)account fileFolder:(NSString *)fileFolder {
+    
+    NSString *path = CachesPath;
+    if (account.length != 0) {
+        path = [NSString stringWithFormat:@"%@/%@/",CachesPath,account];
+    }
+    
+    if (fileFolder.length != 0) {
+        NSString *path1 = [path stringByAppendingPathComponent:fileFolder];
+        NSError *error;
+        if (![[NSFileManager defaultManager] fileExistsAtPath:path1]) {
+            [[NSFileManager defaultManager] createDirectoryAtPath:path1 withIntermediateDirectories:YES attributes:nil error:&error];
+        }
+    }else{
+        NSError *error;
+        if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
+            [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error];
+        }
+    }
+    
+    return [path stringByAppendingPathComponent:fileFolder];
+}
 
 #pragma mark 截图
 /**保存截图保存路径*/

+ 13 - 26
创维盒子/双子星云手机/Vendor/DownLoadManager/SGDwonload/SGCacheManager.m

@@ -43,27 +43,14 @@ static dispatch_semaphore_t _semaphore;
 #pragma mark-plist
 + (NSString *)getNewPlistPath {
     
-    NSString *account = [HWDataManager getStringWithKey:Const_HWAccountPhoneNumber];
-    if (account.length != 0) {
-        NSString *fileFolder = kPath_YunPan_Download_Folder;
-        HLog(@"登录账号:%@", kPath_YunPan_Download_Folder);
-        return [fileFolder stringByAppendingPathComponent:@"downloadInfo.plist"];;
-    }else {
-        HLog(@"获取accout失败 创建下载plist文件失败!");
-        return @"";
-    }
+    NSString *fileFolder = kPath_YunPan_Download_Folder;
+    HLog(@"登录账号:%@", kPath_YunPan_Download_Folder);
+    return [fileFolder stringByAppendingPathComponent:@"downloadInfo.plist"];
 }
 
 + (NSString *)getFullDirector {
 
-    NSString *account = [HWDataManager getStringWithKey:Const_HWAccountPhoneNumber];
-    if (account.length != 0)
-     {
-         return kPath_YunPan_Download_Folder;;
-     }else {
-         HLog(@"获取accout失败 创建下载plist文件失败!");
-         return @"";
-     }
+    return kPath_YunPan_Download_Folder;
 }
 
 + (NSMutableDictionary *)getDownloadList {
@@ -138,15 +125,15 @@ static dispatch_semaphore_t _semaphore;
             filePathAccount = fileArray[fileArray.count - 3];
         }
 
-        NSString *account = [HWDataManager getStringWithKey:Const_HWAccountPhoneNumber];
-        if (account.length == 0) {
-            HLog(@"获取accout失败");
-        }
-
-        if (![filePathAccount isEqualToString:account]) {
-            HLog(@"切换账号 文件缓存账号%@ 与 当前登录账号:%@ 不一致", filePathAccount, account);
-            return NO;
-        }
+//        NSString *account = [HWDataManager getStringWithKey:Const_HWAccountPhoneNumber];
+//        if (account.length == 0) {
+//            HLog(@"获取accout失败");
+//        }
+//
+//        if (![filePathAccount isEqualToString:account]) {
+//            HLog(@"切换账号 文件缓存账号%@ 与 当前登录账号:%@ 不一致", filePathAccount, account);
+//            return NO;
+//        }
     }