Browse Source

1.任务加timer检测

huangxiaodong 1 year ago
parent
commit
0d12dccd02

+ 20 - 0
创维盒子/双子星云手机/Class/Set/uploadFile/uploadFileManager/backupsFileManager.m

@@ -8,6 +8,12 @@
 #import "backupsFileManager.h"
 #import "cachesFileManager.h"
 #import "connectDeviceManager.h"
+
+@interface backupsFileManager ()
+/**检测任务10s后 无反馈重新开始 */
+@property (nonatomic, assign) NSInteger  taskRenewTime; //
+@end
+
 @implementation backupsFileManager
 static backupsFileManager * cur_backupsFileShareInstance = nil;
 +(backupsFileManager *)shareInstance;
@@ -164,6 +170,8 @@ static backupsFileManager * cur_backupsFileShareInstance = nil;
 
 - (void)beginBackupsFileFun
 {
+    self.taskRenewTime = [iTools getNowTimeStamp];
+    
     NSInteger index = _curPhotosBackupsTaskMod.didBackupsCount + _curPhotosBackupsTaskMod.failCount;
     
     if(index >= _curPhotosBackupsTaskMod.LocalIdentifierArr.count){
@@ -294,6 +302,8 @@ static backupsFileManager * cur_backupsFileShareInstance = nil;
 //修改文件上传的状态
 - (void)changeBackupsFileStateWithSpeedFun
 {
+    self.taskRenewTime = [iTools getNowTimeStamp];
+    
     [[NSNotificationCenter defaultCenter] postNotificationName:backupsFileRefreshNotification object:_curPhotosBackupsTaskMod];
 }
 
@@ -340,6 +350,16 @@ static backupsFileManager * cur_backupsFileShareInstance = nil;
         return;
     }
     
+    NSInteger curTime = [iTools getNowTimeStamp];
+    
+    if(self.taskRenewTime == 0){
+        return;
+    }
+    
+    if(curTime - self.taskRenewTime < 10){
+        return;
+    }
+    
     [self beginBackupsFileFun];
 }
 @end

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

@@ -38,6 +38,7 @@ NS_ASSUME_NONNULL_BEGIN
 
 //删除本地数据库记录
 - (void)deleteDownloadFileRecordBy:(NSMutableArray *)delArr withDelCache:(BOOL)isDelCache;
+- (void)checkReDownloadFileFun;
 @end
 
 NS_ASSUME_NONNULL_END

+ 32 - 0
创维盒子/双子星云手机/Class/Set/uploadFile/uploadFileManager/downloadManager.m

@@ -7,6 +7,10 @@
 
 #import "downloadManager.h"
 #import "cachesFileManager.h"
+@interface downloadManager ()
+/**检测任务10s后 无反馈重新开始 */
+@property (nonatomic, assign) NSInteger  taskRenewTime; //
+@end
 
 @implementation downloadManager
 static downloadManager * cur_downloadManager = nil;
@@ -191,6 +195,8 @@ static downloadManager * cur_downloadManager = nil;
 
 - (void)DownloadFileDoneOneFileFun
 {
+    self.taskRenewTime = [iTools getNowTimeStamp];
+    
     _curDownloadFileModel.curDownloadStateType = downloadStateDone;
 //    NSString *fileName = [_curDownloadFileModel getFileNameFun];
 //    [cachesFileManager removeItemAtPath:fileName type:DownLoadFileType error:nil];
@@ -206,6 +212,8 @@ static downloadManager * cur_downloadManager = nil;
 
 - (void)DownloadFileChangeingOneFileFun
 {
+    self.taskRenewTime = [iTools getNowTimeStamp];
+    
     if(_curDownloadFileModel.curDownloadStateType == downloadStateDone){
         [_downLoadFileModelDataArr removeObject:_curDownloadFileModel];
         [self handleDatabaseArrAddObjectInDone:_curDownloadFileModel];
@@ -364,4 +372,28 @@ static downloadManager * cur_downloadManager = nil;
     [[NSNotificationCenter defaultCenter] postNotificationName:downloadFileRefreshNotification object:_curDownloadFileModel];
     
 }
+
+//检查是否需要重新下载
+- (void)checkReDownloadFileFun
+{
+    if(!_curDownloadFileModel){
+        return;
+    }
+    
+    if(_curDownloadFileModel.curDownloadStateType != downloadStateUploading){
+        return;
+    }
+    
+    NSInteger curTime = [iTools getNowTimeStamp];
+    
+    if(self.taskRenewTime == 0){
+        return;
+    }
+    
+    if(curTime - self.taskRenewTime < 10){
+        return;
+    }
+    
+    [[NSNotificationCenter defaultCenter] postNotificationName:downloadFileBeginNotification object:_curDownloadFileModel];
+}
 @end

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

@@ -53,6 +53,8 @@ NS_ASSUME_NONNULL_BEGIN
 
 //删除本地数据库记录
 - (void)deleteUploadFileRecordBy:(NSMutableArray *)delArr withDelCache:(BOOL)isDelCache complete:(custom_complete_B)complete;
+
+- (void)checkReUploadFileFun;
 @end
 
 NS_ASSUME_NONNULL_END

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

@@ -8,6 +8,10 @@
 #import "uploadFileManager.h"
 #import <AssetsLibrary/AssetsLibrary.h>
 #import "photosBackupsTaskModel.h"
+@interface uploadFileManager ()
+/**检测任务10s后 无反馈重新开始 */
+@property (nonatomic, assign) NSInteger  taskRenewTime; //
+@end
 
 @implementation uploadFileManager
 static uploadFileManager * cur_uploadFileShareInstance = nil;
@@ -368,6 +372,8 @@ static uploadFileManager * cur_uploadFileShareInstance = nil;
         return;
     }
     
+    self.taskRenewTime = [iTools getNowTimeStamp];
+    
     _curUploadFileDataModel.curUploadStateType = curUploadStateType;
     _curUploadFileDataModel.didUploadBytes = didUpLoadBytes;
     
@@ -391,7 +397,7 @@ static uploadFileManager * cur_uploadFileShareInstance = nil;
     }];
         
     
-    if(!_isSuspendType || curUploadStateType == uploadStateSuspend){
+    if(!_isSuspendType || curUploadStateType != uploadStateSuspend){
         [[NSNotificationCenter defaultCenter] postNotificationName:uploadFileRefreshNotification object:model];
     }
     
@@ -458,12 +464,7 @@ static uploadFileManager * cur_uploadFileShareInstance = nil;
             uploadingArr = _databaseArr[2];
         }
         
-        for (uploadFileDataModel *baseUploadFileDataMod in uploadingArr) {
-            if(delModel.bg_id.integerValue == baseUploadFileDataMod.bg_id.integerValue){
-                [uploadingArr removeObject:baseUploadFileDataMod];
-                break;
-            }
-        }
+        [uploadingArr removeObject:delModel];
     }
 }
 
@@ -483,6 +484,14 @@ static uploadFileManager * cur_uploadFileShareInstance = nil;
     }
 }
 
+- (void)handleDatabaseArrAddModelInUploading:(uploadFileDataModel*)uploadmodel
+{
+    if(_databaseArr && _databaseArr.count == 3 ){
+        NSMutableArray *uploadlingArr = _databaseArr[0];
+        [uploadlingArr insertObject:uploadmodel atIndex:0];
+    }
+}
+
 //暂停上传完成
 - (void)suspendUploadFileFun:(BOOL)isSuspendAll
 {
@@ -545,6 +554,7 @@ static uploadFileManager * cur_uploadFileShareInstance = nil;
         
         if(needAddModel){
             [_fileModelDataArr addObject:addModel];
+            [self handleDatabaseArrAddModelInUploading:addModel];
         }
     }
     
@@ -556,9 +566,11 @@ static uploadFileManager * cur_uploadFileShareInstance = nil;
 {
     long totalSizeByte = _curUploadFileDataModel.totalBytes;
     
+    [self handleDatabaseArrByDelete:_curUploadFileDataModel];
+    
     [self changeUploadFileState:uploadStateDone withDidUploadBytes:totalSizeByte withModel:_curUploadFileDataModel complete:^(BOOL isSuccess) {
         [self->_fileModelDataArr removeObject:self->_curUploadFileDataModel];
-         
+        
         self->_isUploadIngType = NO;
         if(self->_fileModelDataArr.count > 0){
             [self beginUploadFileFun];
@@ -740,5 +752,27 @@ static uploadFileManager * cur_uploadFileShareInstance = nil;
     [lock unlock];
 }
 
-
+//检查是否需要重新上传
+- (void)checkReUploadFileFun
+{
+    if(!_curUploadFileDataModel){
+        return;
+    }
+    
+    if(_curUploadFileDataModel.curUploadStateType != uploadStateUploading){
+        return;
+    }
+    
+    NSInteger curTime = [iTools getNowTimeStamp];
+    
+    if(self.taskRenewTime == 0){
+        return;
+    }
+    
+    if(curTime - self.taskRenewTime < 10){
+        return;
+    }
+    
+    [[NSNotificationCenter defaultCenter] postNotificationName:uploadFileBeginNotification object:_curUploadFileDataModel];;
+}
 @end

+ 6 - 3
创维盒子/双子星云手机/Class/Set/uploadFile/uploadFileView/uploadFileRecordTableView.m

@@ -352,7 +352,7 @@
     
         
      if(_failHeadView){
-        NSString *leftStr =  NSLocalizedString(@"File_upload_Record_did_upload",nil);
+        NSString *leftStr =  NSLocalizedString(@"File_upload_Record_upload_fail",nil);
         NSString *rightStr =  NSLocalizedString(@"File_upload_Record_clear_Record",nil);
         NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_uploadfailArr.count];
 
@@ -481,8 +481,11 @@
 #pragma mark 处理上传中的 状态点击事件
 - (void)handleUploadFailStateWith:(uploadFileDataModel*)model{
     
-    [_curDataArr removeObject:model];
-    [self reloadDataFun];
+    if(_uploadfailArr && _uploadfailArr.count > 0){
+        [_uploadfailArr removeObject:model];
+    }
+   
+    [self RefreshAllDataFun];
     
     if(_didClickReUploadBlock){
         _didClickReUploadBlock(model);

+ 1 - 1
创维盒子/双子星云手机/CloudPlayer/PlayerViewController+otherDelegate.h

@@ -36,7 +36,7 @@ NS_ASSUME_NONNULL_BEGIN
 
 - (void)handleDownloadResponseFunBy:(id)message;
 
-- (void)checkOtherTaskFun;
+- (void)checkAllTaskFun;
 @end
 
 NS_ASSUME_NONNULL_END

+ 8 - 2
创维盒子/双子星云手机/CloudPlayer/PlayerViewController+otherDelegate.mm

@@ -16,6 +16,8 @@
 #import "HaveNewVersionView.h"
 #import "connectDeviceManager.h"
 #import "PlayerViewController+downloadFile.h"
+#import "downloadManager.h"
+#import "uploadFileManager.h"
 
 @implementation PlayerViewController (otherDelegate)
 
@@ -320,9 +322,13 @@
     
 }
 
-- (void)checkOtherTaskFun
+- (void)checkAllTaskFun
 {
-
+    //处理相册备份
+    [[backupsFileManager shareInstance] checkReBackupsFileFun];
+    
+    [[uploadFileManager shareInstance] checkReUploadFileFun];
+    [[downloadManager shareInstance] checkReDownloadFileFun];
 }
 
 @end

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

@@ -68,7 +68,7 @@
                         //
                         //    }];
                             
-                            if([fileLengthNum integerValue] == self.curUploadFileDataMod.totalBytes){
+                            if([fileLengthNum integerValue] == self.curUploadFileDataMod.totalBytes && self.curUploadFileDataMod.totalBytes != 0){
                                 self.taskUid = nil;
                                 
                                 NSMutableArray *delArr = [NSMutableArray new];

+ 31 - 18
创维盒子/双子星云手机/CloudPlayer/PlayerViewController.mm

@@ -144,6 +144,8 @@ ComontAlretViewControllerDelegate>
 @property (nonatomic, assign) NSInteger          currentTime;
 /**定时器计数*/
 @property (nonatomic, assign) NSInteger          webSocketTime;
+/**定时器计数 任务检测*/
+@property (nonatomic, assign) NSInteger          webSocketTaskTime;
 
 /**是否是收入进入云手机*/
 @property (nonatomic, assign) BOOL          isFirstEnterPhone;
@@ -274,8 +276,7 @@ ComontAlretViewControllerDelegate>
     [self connectVideoServer];
     [self opencommandChannelManagerrc_openURL];
     
-//    _timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerChange) userInfo:nil repeats:YES];
-//    [[NSRunLoop currentRunLoop] addTimer:_timer forMode:NSRunLoopCommonModes];
+
 }
 
 - (void)initData
@@ -337,16 +338,16 @@ ComontAlretViewControllerDelegate>
         [[[[UIApplication sharedApplication] keyWindow] viewWithTag:1235] removeFromSuperview];
     }
     
-    // 销毁定时器
-    [self cancelTimer];
-    
     [self enablePanRightBack];
+    // 屏幕常亮
+    [UIApplication sharedApplication].idleTimerDisabled = NO;
+    [[UIApplication sharedApplication] setStatusBarHidden:NO];
     
     // 播放器内部页面跳转-不能回收的资源
     if (self.isNeedRecyclResource) {
-        // 屏幕常亮
-        [UIApplication sharedApplication].idleTimerDisabled = NO;
-        [[UIApplication sharedApplication] setStatusBarHidden:NO];
+        
+        // 销毁定时器
+        [self cancelTimer];
         
         if (USEAAC)
         {
@@ -385,11 +386,6 @@ ComontAlretViewControllerDelegate>
             forceStartTimer = nil;
         }
         
-        if(_timer){
-            [_timer invalidate];
-            _timer = nil;
-        }
-        
         if(_checkThridConnectTimer){
             [_checkThridConnectTimer invalidate];
             _checkThridConnectTimer = nil;
@@ -1013,6 +1009,8 @@ ComontAlretViewControllerDelegate>
 
 - (void)liveStreamManagerOutPut:(RCLiveSteamManager *)manager didOutPutVideoPixelBuffer:(CVPixelBufferRef)pixelBuffer {
     
+    mySelf.concentTime = [iTools getNowTimeStamp];
+    
     if(!_canShowImgAndVoiceType){
         return;
     }
@@ -1059,7 +1057,7 @@ ComontAlretViewControllerDelegate>
                 {
                     [mySelf showImageUIImageViewWithCIImage:ciImage pixelBufferRef:pixelBuffer];/*使用UIImageView渲染*/
                     
-                    mySelf.concentTime = [iTools getNowTimeStamp];
+                    //mySelf.concentTime = [iTools getNowTimeStamp];
                     mySelf.isConnectSuccess = YES;
                 }
             }
@@ -1650,7 +1648,6 @@ NSDate *lastVideoTome;/*上一帧数据时间*/
         });
     }
     
-    
     //处理相册备份
     [[backupsFileManager shareInstance] AutohandlePhotosBackupsFun];
 }
@@ -2817,6 +2814,7 @@ static int  couneeee = 0;
     self.concentTime = [iTools getNowTimeStamp];
     self.currentTime = 0;
     self.webSocketTime = 0;
+    self.webSocketTaskTime = 0;
     
     _timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerChange) userInfo:nil repeats:YES];
     [[NSRunLoop currentRunLoop] addTimer:_timer forMode:NSRunLoopCommonModes];
@@ -2824,8 +2822,10 @@ static int  couneeee = 0;
 
 - (void)cancelTimer {
     // 取消定时器
-    [_timer invalidate];
-    _timer = nil;
+    if(_timer){
+        [_timer invalidate];
+        _timer = nil;
+    }
 }
 
 - (void)timerChange {
@@ -2840,11 +2840,24 @@ static int  couneeee = 0;
     //处理websockt是否断开
     self.webSocketTime++;
     
+    //处理其他任务
+    self.webSocketTaskTime++;
+    
     if(self.webSocketTime > 8)
     {
         [self WebSocketNeedRelinkFun];
     }
-    //HLog(@"webSocketTime %ld",self.webSocketTime);
+    
+    if(self.webSocketTaskTime > 10)
+    {
+        self.webSocketTaskTime = 0;
+        [self checkAllTaskFun];
+        
+        NSString *commondStr  = @"{\"type\":\"forwardMsg\",\"data\":\"offline_notification\"}";
+        [self send_data:commondStr];
+    }
+    
+    //HLog(@"webSocketTime %ld",self.webSocketTaskTime);
 }
 
 // 3、30s之后 没有收到拉流数据 自动断开链接