Pārlūkot izejas kodu

1.控制下载刷新频率

huangxiaodong 1 gadu atpakaļ
vecāks
revīzija
741fd97f26

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

@@ -488,16 +488,19 @@ totalBytesExpectedToSend:(int64_t)totalBytesExpectedToSend {
     [[NSNotificationCenter defaultCenter] postNotificationName:customDownloadTaskExeError object:nil userInfo:@{@"operation" : operation}];
 }
 
-//外面的下载数据跳的太频繁 控制下
-static int DownloadTaskExeingNotNum = 0;
-
 // 重启某一个operation 保存本地 通知外界
 - (void)operationDoningWithOperation:(customDownloadOperation *)operation {
     HLog(@"DownloadTaskExeing");
     
-    DownloadTaskExeingNotNum ++;
-    if (DownloadTaskExeingNotNum >= 10) {
-        DownloadTaskExeingNotNum = 0;
+    NSTimeInterval curTime = [[NSDate date] timeIntervalSince1970];
+    NSTimeInterval timeDiff = curTime - operation.preNotTimeInterval;
+    
+    HLog(@"控制刷新时间为1秒:%f",timeDiff);
+    
+    if (operation.preNotTimeInterval <= 0
+        || timeDiff > 0.8 ) {
+        
+        operation.preNotTimeInterval = curTime;
         [[NSNotificationCenter defaultCenter] postNotificationName:customDownloadTaskExeing object:nil userInfo:@{@"operation" : operation}];
     }
 }

+ 3 - 0
创维盒子/双子星云手机/Class/Set/uploadFile/customDownloadManager/customDownloadOperation.h

@@ -63,6 +63,9 @@ NS_ASSUME_NONNULL_BEGIN
 /** 是否完成 */
 @property (nonatomic, assign)  NSInteger isFinished;
 
+/** 下载中上次通知的时间  用来控制通知时间的频率 目前定位一秒 */
+@property (nonatomic, assign) NSTimeInterval  preNotTimeInterval;
+
 // 创建下载操作任务
 - (instancetype)initWith:(NSString *)url session:(NSURLSession *)session;
 // downloadType 不传 即为原来的 分享链接唤起的下载

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

@@ -538,7 +538,7 @@
     
     KWeakSelf
     dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
-        [weakSelf updateDataDownloadingBy:_curCouldPhoneFileModel];
+        [weakSelf updateDataDownloadingBy:self->_curCouldPhoneFileModel];
     });
 }
 

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

@@ -411,7 +411,7 @@ totalBytesExpectedToSend:(int64_t)totalBytesExpectedToSend {
     
     // 获得已经下载的文件大小
     operation.currentSize += data.length;
-    HLog(@"currentSize:%lld---progress:%.2f", operation.currentSize, 1.00*operation.currentSize/operation.totalSize);
+    HLog(@"当前线程:%@ -----currentSize:%lld---progress:%.2f",[NSThread currentThread], operation.currentSize, 1.00*operation.currentSize/operation.totalSize);
 
     // 写入文件
     if(operation.handle){
@@ -488,16 +488,21 @@ totalBytesExpectedToSend:(int64_t)totalBytesExpectedToSend {
     [[NSNotificationCenter defaultCenter] postNotificationName:nasDownloadTaskExeError object:nil userInfo:@{@"operation" : operation}];
 }
 
-//外面的下载数据跳的太频繁 控制下
-static int nasDownloadTaskExeingNotNum = 0;
+
 
 // 重启某一个operation 保存本地 通知外界
 - (void)operationDoningWithOperation:(customDownloadOperation *)operation {
     HLog(@"DownloadTaskExeing");
     
-    nasDownloadTaskExeingNotNum ++;
-    if (nasDownloadTaskExeingNotNum >= 30) {
-        nasDownloadTaskExeingNotNum = 0;
+    NSTimeInterval curTime = [[NSDate date] timeIntervalSince1970];
+    NSTimeInterval timeDiff = curTime - operation.preNotTimeInterval;
+    
+    HLog(@"控制刷新时间为1秒:%f",timeDiff);
+    
+    if (operation.preNotTimeInterval <= 0
+        || timeDiff > 0.8 ) {
+        
+        operation.preNotTimeInterval = curTime;
         [[NSNotificationCenter defaultCenter] postNotificationName:nasDownloadTaskExeing object:nil userInfo:@{@"operation" : operation}];
     }
 }