소스 검색

1.上传下载刷新时间优化

huangxiaodong 8 달 전
부모
커밋
b7620e0af4

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

@@ -497,9 +497,13 @@ totalBytesExpectedToSend:(int64_t)totalBytesExpectedToSend {
     NSTimeInterval timeDiff = curTime - operation.preNotTimeInterval;
     
     HLog(@"控制刷新时间为1秒:%f",timeDiff);
+    CGFloat RefreshTimer = 0.8;
+    if(operation.totalSize <= 5*1024*1024){//小于5M 
+        RefreshTimer = 0.2;
+    }
     
     if (operation.preNotTimeInterval <= 0
-        || timeDiff > 0.8 ) {
+        || timeDiff > RefreshTimer ) {
         
         operation.preNotTimeInterval = curTime;
         [[NSNotificationCenter defaultCenter] postNotificationName:customDownloadTaskExeing object:nil userInfo:@{@"operation" : operation}];

+ 35 - 19
创维盒子/双子星云手机/NAS/nasDownloadManager/nasDownloadFileManager.m

@@ -6,6 +6,10 @@
 //
 
 #import "nasDownloadFileManager.h"
+@interface nasDownloadFileManager ()
+@property (nonatomic, strong)NSLock *lock;
+
+@end
 
 @implementation nasDownloadFileManager
 static nasDownloadFileManager * cur_nasDownloadFileManager = nil;
@@ -29,6 +33,7 @@ static nasDownloadFileManager * cur_nasDownloadFileManager = nil;
         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskFinishedNoti:) name:nasDownloadTaskExeEnd object:nil];
         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskFinishedNoti:) name:nasDownloadTaskExeError object:nil];
         
+        _lock = [[NSLock alloc] init];
         [self initDownloadManagerFun];
     }
     
@@ -342,25 +347,29 @@ static nasDownloadFileManager * cur_nasDownloadFileManager = nil;
 
     if(!model)return;
     
-    if (model.downloadState == customDownloadStateCompleted) {
-        
-        //1.先做数据保存
-        NSDictionary *dataDict = [model downLoadInfoWithFinished:YES];
-        [self saveFileInfoWithDict:dataDict with:model.url];
+    //globalBlock(^{
+        if (model.downloadState == customDownloadStateCompleted) {
+            
+            //1.先做数据保存
+            NSDictionary *dataDict = [model downLoadInfoWithFinished:YES];
+            [self saveFileInfoWithDict:dataDict with:model.url];
+            
+            [self handldDownloadDoneDataBy:model];
+            
+            HLog(@"handldDownloadDoneDataBy done")
+        }
+        else if (model.downloadState == customDownloadStateFailed){
+            [self handldDownloadFailDataBy:model];
+        }
         
-        [self handldDownloadDoneDataBy:model];
+        mainBlock(^{
+            [[NSNotificationCenter defaultCenter] postNotificationName:nasDownloadTaskFinishedNotification object:model];
+            
+            [[webRtcManager shareManager] NasDownloadTaskFinishedNoti:model];
+        });
         
-        HLog(@"handldDownloadDoneDataBy done")
-    }
-    else if (model.downloadState == customDownloadStateFailed){
-        [self handldDownloadFailDataBy:model];
-    }
+   // });
     
-    mainBlock(^{
-        [[NSNotificationCenter defaultCenter] postNotificationName:nasDownloadTaskFinishedNotification object:model];
-        
-        [[webRtcManager shareManager] NasDownloadTaskFinishedNoti:model];
-    });
 }
 
 
@@ -657,17 +666,19 @@ static nasDownloadFileManager * cur_nasDownloadFileManager = nil;
 /**  增加配置信息 */
 - (BOOL)saveFileInfoWithDict:(NSDictionary *)dict with:(NSString*)url {
     
+    HLog(@"saveFileInfoWithDict")
+    
     if(!dict || !url){
         return NO;
     }
     
     BOOL flag = NO;
-    @synchronized (self) {
+    [_lock lock];
         NSString *key = url;
         NSMutableDictionary *dictM =  [self getDownloadDownList];
         [dictM setObject:dict forKey:key];
         flag = [dictM writeToFile:[self getDownloadDonePlistPath] atomically:YES];
-    }
+    [_lock unlock];
     
     return flag;
     
@@ -710,6 +721,7 @@ static nasDownloadFileManager * cur_nasDownloadFileManager = nil;
 #pragma mark-查询还有没有没处理的任务
 - (void)checkDownloadDonePlistInfoFun
 {
+    HLog(@"checkDownloadDonePlistInfoFun")
     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{
         NSMutableDictionary *dictM =  [[self getDownloadDownList] mutableCopy];
         NSMutableArray *needDeletekeyArr = [NSMutableArray array];
@@ -737,9 +749,13 @@ static nasDownloadFileManager * cur_nasDownloadFileManager = nil;
         
         if(needDeletekeyArr.count > 0){
             for(NSString*key in needDeletekeyArr){
-                [self deleteFileInfoWithUrl:key];
+                //[self deleteFileInfoWithUrl:key];
                 [dictM removeObjectForKey:key];
             }
+            
+            //保存更新本地数据
+            [dictM writeToFile:[self getDownloadDonePlistPath] atomically:YES];
+            
             [needDeletekeyArr removeAllObjects];
         }
             

+ 5 - 1
创维盒子/双子星云手机/NAS/nasDownloadManager/nasDownloadManager.m

@@ -589,9 +589,13 @@ totalBytesExpectedToSend:(int64_t)totalBytesExpectedToSend {
     NSTimeInterval timeDiff = curTime - operation.preNotTimeInterval;
     
     HLog(@"控制刷新时间为1秒:%f",timeDiff);
+    CGFloat RefreshTimer = 0.8;
+    if(operation.totalSize <= 5*1024*1024){//小于5M 事实
+        RefreshTimer = 0.2;
+    }
     
     if (operation.preNotTimeInterval <= 0
-        || timeDiff > 0.5 ) {
+        || timeDiff > RefreshTimer ) {
         
         HLog(@"下载发送刷新通知:%f",timeDiff);
         operation.preNotTimeInterval = curTime;

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

@@ -804,8 +804,13 @@ didReceiveResponse:(NSURLResponse *)response
             
             //HLog(@"控制刷新时间为1秒:%f",timeDiff);
             
+            CGFloat RefreshTimer = 0.8;
+            if(operation.fileModel.totalBytes <= 5*1024*1024){//小于5M 事实
+                RefreshTimer = 0.2;
+            }
+            
             if (operation.preNotTimeInterval <= 0
-                || timeDiff > 0.8 ) {
+                || timeDiff > RefreshTimer ) {
                 
                 operation.preNotTimeInterval = curTime;
                 [[NSNotificationCenter defaultCenter] postNotificationName:uploadFileUploadingNotification object:operation.fileModel];