Parcourir la source

1.修复心跳包Timer重复创建。
2.修复超时登出后重复Present Login View。

Pen Li il y a 9 ans
Parent
commit
7ae96d3b4b

BIN
Ants Contract/AntsContract.xcworkspace/xcuserdata/macmini1.xcuserdatad/UserInterfaceState.xcuserstate


+ 34 - 0
Ants Contract/AntsContract.xcworkspace/xcuserdata/macmini1.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -2,4 +2,38 @@
 <Bucket
    type = "0"
    version = "2.0">
+   <Breakpoints>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            shouldBeEnabled = "No"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "common/ACNetwork.m"
+            timestampString = "513582137.593489"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "760"
+            endingLineNumber = "760"
+            landmarkName = "+heartBeat"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            shouldBeEnabled = "No"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "common/AppDelegate.m"
+            timestampString = "513588311.544328"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "354"
+            endingLineNumber = "354"
+            landmarkName = "-heartBeatRightNow:"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
+   </Breakpoints>
 </Bucket>

+ 7 - 7
Ants Contract/Granite Expo eSign/Granite Expo eSign/config.h

@@ -39,13 +39,13 @@
 
 
     #define  URL_ERR_LOG  @""
-    #define  URL_UPDATE_AUTH  @"http://192.168.0.155/phpcms/admin.php"
-    #define  URL_UPLOAD_PDF  @"http://192.168.0.155/phpcms/admin.php"
-    #define  URL_LOGOUT  @"http://192.168.0.155/phpcms/admin.php"
-    #define  URL_NEW_DOCUMENT  @"http://192.168.0.155/phpcms/admin.php"
-    #define  URL_UPDATE_NOTES  @"http://192.168.0.155/phpcms/admin.php"
-    #define  URL_REQUEST_DOC  @"http://192.168.0.155/phpcms/admin.php"
-    #define URL_HEART_BEAT @"http://192.168.0.155/phpcms/admin.php"
+    #define  URL_UPDATE_AUTH  @"http://192.168.0.155/cms/phpcms/admin.php"
+    #define  URL_UPLOAD_PDF  @"http://192.168.0.155/cms/phpcms/admin.php"
+    #define  URL_LOGOUT  @"http://192.168.0.155/cms/phpcms/admin.php"
+    #define  URL_NEW_DOCUMENT  @"http://192.168.0.155/cms/phpcms/admin.php"
+    #define  URL_UPDATE_NOTES  @"http://192.168.0.155/cms/phpcms/admin.php"
+    #define  URL_REQUEST_DOC  @"http://192.168.0.155/cms/phpcms/admin.php"
+    #define URL_HEART_BEAT @"http://192.168.0.155/cms/phpcms/admin.php"
 #else
     #define  URL_ERR_LOG  @""
     #define  URL_UPDATE_AUTH  @"https://www.thegraniteexpo.com/admin.php"

+ 33 - 7
Ants Contract/common/AppDelegate.m

@@ -246,7 +246,7 @@
 - (void)applicationDidBecomeActive:(UIApplication *)application {
     // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
     
-    if (self.bLogin) {
+    if (self.bLogin && !self.heartBeat) {
          [self startHeartBeat];
     }
     
@@ -319,6 +319,9 @@
         
         NSTimeInterval timeInterval = [curTime timeIntervalSinceDate:preTime];
         NSTimeInterval timeOutInterval = 1 * 60 * 60;
+#ifdef DEBUG
+        timeOutInterval = 1 * 60;
+#endif
         if (timeInterval > timeOutInterval) {
             return YES;
         }
@@ -332,10 +335,23 @@
         [self heartBeatAction:nil];
     }
     
+//    if(self.heartBeat) {
+//        self.heartBeat.fireDate = [NSDate distantPast];
+//        return;
+//    }
+    
     NSTimeInterval heartBeatTimeInterval = 3 * 60;
+#ifdef DEBUG
+    heartBeatTimeInterval = 30;
+#endif
+    __weak typeof(self) weakself = self;
     dispatch_async(dispatch_get_global_queue(0, 0), ^{
-        self.heartBeat = [NSTimer scheduledTimerWithTimeInterval:heartBeatTimeInterval target:self selector:@selector(heartBeatAction:) userInfo:nil repeats:YES];
-        [[NSRunLoop currentRunLoop] addTimer:self.heartBeat forMode:NSDefaultRunLoopMode];
+        if (weakself.heartBeat) {
+            [weakself.heartBeat invalidate];
+            weakself.heartBeat = nil;
+        }
+        weakself.heartBeat = [NSTimer scheduledTimerWithTimeInterval:heartBeatTimeInterval target:weakself selector:@selector(heartBeatAction:) userInfo:nil repeats:YES];
+        [[NSRunLoop currentRunLoop] addTimer:weakself.heartBeat forMode:NSDefaultRunLoopMode];
         [[NSRunLoop currentRunLoop] run];
     });
 
@@ -351,19 +367,23 @@
 
 - (void)stopHeartBeat {
     if (self.heartBeat) {
+
+//        self.heartBeat.fireDate = [NSDate distantFuture];
         [self.heartBeat invalidate];
         self.heartBeat = nil;
     }
 }
 
+
 - (void)heartBeatTimeout {
     __weak typeof(self) weakself = self;
     dispatch_async(dispatch_get_main_queue(), ^{
         
+        
         UIApplication *application = [UIApplication sharedApplication];
         UINavigationController *rootVC = (UINavigationController *)application.keyWindow.rootViewController;
         
-        // 超时登出
+        // 超时登出,登出中停止心跳
         [weakself Logout];
         // 提示登录
         UIViewController* presentVC=rootVC.presentedViewController;
@@ -373,14 +393,20 @@
                 [rootVC popToRootViewControllerAnimated:NO];
                 RootViewController* topvc= (RootViewController*)rootVC.topViewController;
                 [topvc dealWithUILogout];
-                [topvc presentLogin:topvc.ibSignin];
+                dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, 0.25 * NSEC_PER_SEC);
+                dispatch_after(time, dispatch_get_main_queue(), ^{
+                    [topvc presentLogin:topvc.ibSignin];
+                });
             }];
         } else {
             // 退回到初始视图
             [rootVC popToRootViewControllerAnimated:NO];
             RootViewController* topvc= (RootViewController*)rootVC.topViewController;
             [topvc dealWithUILogout];
-            [topvc presentLogin:topvc.ibSignin];
+            dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, 0.25 * NSEC_PER_SEC);
+            dispatch_after(time, dispatch_get_main_queue(), ^{
+                [topvc presentLogin:topvc.ibSignin];
+            });
         }
         
         
@@ -409,7 +435,7 @@
             [weakself heartBeatTimeout];
         }
         
-        DebugLog(@"heart beat result %d",result);
+        NSLog(@"heart beat result %d",result);
         
     });
 }

+ 6 - 3
Ants Contract/common/RootViewController.m

@@ -20,6 +20,8 @@
 
 @interface RootViewController ()
 
+@property (nonatomic,assign) BOOL hasShowLoginVC;
+
 @end
 
 @implementation RootViewController
@@ -55,7 +57,8 @@
 }
 -(void) presentLogin:(id)sender
 {
-    
+    if (self.hasShowLoginVC) return;
+        
     UIBarButtonItem* bbitem = sender;
     
     AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
@@ -64,7 +67,7 @@
         loginvc.returnValue = ^(bool blogin){
             
             //            [self checklogin :true];
-            
+            self.hasShowLoginVC = NO;
             if(blogin)
             {
                 
@@ -138,7 +141,7 @@
         [self presentViewController:navi animated:YES completion:^{
             
             DebugLog(@"login present.........");
-            
+            self.hasShowLoginVC = YES;
         }];
     }
 }