瀏覽代碼

1.减少timer 或者增大timer的轮询时间

huangxiaodong 11 月之前
父節點
當前提交
9d5a21a5e3

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

@@ -27,8 +27,6 @@ ShowImageViewDelegate>{
     UIButton *backBtn;
     
     UIButton *showHomeBtn;
-    
-    NSTimer *hideBottomTimer;
 }
 
 @end
@@ -570,20 +568,18 @@ static CGRect startFrame;
     if(mueBtn.hidden){
         [self setShowOrHideBottomButtonsFunBy:NO];
         
-        [hideBottomTimer invalidate];
-        hideBottomTimer = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(timerToHideBottomButtonFun) userInfo:nil repeats:NO];
-        [[NSRunLoop currentRunLoop] addTimer:hideBottomTimer forMode:NSRunLoopCommonModes];
+        KWeakSelf
+        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+            [weakSelf timerToHideBottomButtonFun];
+        });
     }
     else{
         [self setShowOrHideBottomButtonsFunBy:YES];
-        [hideBottomTimer invalidate];
     }
 }
 
 - (void)timerToHideBottomButtonFun
 {
-    [hideBottomTimer invalidate];
-    
     if(!isLan){
         return;
     }

+ 9 - 10
创维盒子/双子星云手机/cloudPhone/websocket/webSocketManager.m

@@ -28,7 +28,7 @@
 @property (nonatomic, assign) NSInteger      webSocketTime;
 /**定时器计数 任务检测*/
 @property (nonatomic, assign) NSInteger          webSocketTaskTime;
-@property (nonatomic, copy)   NSTimer            *timer; // 定时器-控制按钮
+@property (nonatomic, copy)   NSTimer            *webSocketCheckTimer; // 定时器-控制按钮
 //第一次链接设备 要发送指令信息 实现单点登录
 @property (nonatomic, assign)BOOL didSendfristMsg;
 
@@ -50,13 +50,13 @@ static webSocketManager *webSocketManagerInstance = nil;
 
 - (void)initOtherFun
 {
-    if(_timer){
+    if(_webSocketCheckTimer){
         //[_timer invalidate];
         return;
     }
     
-    _timer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(timerChange) userInfo:nil repeats:YES];
-    [[NSRunLoop currentRunLoop] addTimer:_timer forMode:NSRunLoopCommonModes];
+    _webSocketCheckTimer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(webScoketTimerChange) userInfo:nil repeats:YES];
+    [[NSRunLoop currentRunLoop] addTimer:_webSocketCheckTimer forMode:NSRunLoopCommonModes];
     
     commandSendCheckArr = [NSMutableArray new];
 }
@@ -359,21 +359,20 @@ static webSocketManager *webSocketManagerInstance = nil;
     }
 }
 
-- (void)timerChange {
+- (void)webScoketTimerChange {
     
-   
     //处理websockt是否断开
-    self.webSocketTime += 2;
+    self.webSocketTime += 5;
     
     //处理其他任务
-    self.webSocketTaskTime += 2;
+    self.webSocketTaskTime += 5;
     
-    if(self.webSocketTime > 8)
+    if(self.webSocketTime >= 10)
     {
         [self WebSocketNeedRelinkFun];
     }
     
-    if(self.webSocketTaskTime > 10)
+    if(self.webSocketTaskTime >= 10)
     {
         self.webSocketTaskTime = 0;
         [self checkAllTaskFun];