Browse Source

1.控制上传刷新频率

huangxiaodong 1 year ago
parent
commit
294d0ecbd3

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

@@ -30,6 +30,10 @@ NS_ASSUME_NONNULL_BEGIN
 @property(nonatomic,assign) NSInteger  i;//从来控制速度刷新的
 
 @property(nonatomic,assign) BOOL  isCancelType;//是都被点击暂停或者删除了(考虑dataTask取消的情况)
+
+/** 下载中上次通知的时间  用来控制通知时间的频率 目前定位一秒 */
+@property (nonatomic, assign) NSTimeInterval  preNotTimeInterval;
+
 @end
 
 NS_ASSUME_NONNULL_END

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

@@ -19,7 +19,6 @@
 //正在下载的上传地址数组
 @property(nonatomic,strong) NSMutableArray *uploadingOperationArr;
 
-@property(nonatomic,assign) NSInteger speedShowCount;//内网的情况 多少次才刷新一次
 @end
 
 @implementation nasMixUploadManager
@@ -37,13 +36,6 @@
     if (self = [super init]) {
         _maxUploadLoadCount = 2;
         
-       if ([connectDeviceManager shareInstance].isPingOk)
-       {
-           _speedShowCount = 3;
-       }
-       else{
-           _speedShowCount = 0;
-       }
         //[self registeNotification];
     }
     return self;
@@ -753,10 +745,16 @@ didReceiveResponse:(NSURLResponse *)response
                 operation.fileModel.didUploadBytes -= (totalBytesExpectedToSend - operation.onceDataLengt);
             }
             
-            operation.i ++;
-            if(operation.i >= _speedShowCount){
+            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:uploadFileRefreshNotification object:operation.fileModel];
-                operation.i = 0;
             }
             
             break;