|
@@ -246,7 +246,7 @@
|
|
|
- (void)applicationDidBecomeActive:(UIApplication *)application {
|
|
- (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.
|
|
// 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];
|
|
[self startHeartBeat];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -319,6 +319,9 @@
|
|
|
|
|
|
|
|
NSTimeInterval timeInterval = [curTime timeIntervalSinceDate:preTime];
|
|
NSTimeInterval timeInterval = [curTime timeIntervalSinceDate:preTime];
|
|
|
NSTimeInterval timeOutInterval = 1 * 60 * 60;
|
|
NSTimeInterval timeOutInterval = 1 * 60 * 60;
|
|
|
|
|
+#ifdef DEBUG
|
|
|
|
|
+ timeOutInterval = 1 * 60;
|
|
|
|
|
+#endif
|
|
|
if (timeInterval > timeOutInterval) {
|
|
if (timeInterval > timeOutInterval) {
|
|
|
return YES;
|
|
return YES;
|
|
|
}
|
|
}
|
|
@@ -332,10 +335,23 @@
|
|
|
[self heartBeatAction:nil];
|
|
[self heartBeatAction:nil];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// if(self.heartBeat) {
|
|
|
|
|
+// self.heartBeat.fireDate = [NSDate distantPast];
|
|
|
|
|
+// return;
|
|
|
|
|
+// }
|
|
|
|
|
+
|
|
|
NSTimeInterval heartBeatTimeInterval = 3 * 60;
|
|
NSTimeInterval heartBeatTimeInterval = 3 * 60;
|
|
|
|
|
+#ifdef DEBUG
|
|
|
|
|
+ heartBeatTimeInterval = 30;
|
|
|
|
|
+#endif
|
|
|
|
|
+ __weak typeof(self) weakself = self;
|
|
|
dispatch_async(dispatch_get_global_queue(0, 0), ^{
|
|
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];
|
|
[[NSRunLoop currentRunLoop] run];
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -351,19 +367,23 @@
|
|
|
|
|
|
|
|
- (void)stopHeartBeat {
|
|
- (void)stopHeartBeat {
|
|
|
if (self.heartBeat) {
|
|
if (self.heartBeat) {
|
|
|
|
|
+
|
|
|
|
|
+// self.heartBeat.fireDate = [NSDate distantFuture];
|
|
|
[self.heartBeat invalidate];
|
|
[self.heartBeat invalidate];
|
|
|
self.heartBeat = nil;
|
|
self.heartBeat = nil;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
- (void)heartBeatTimeout {
|
|
- (void)heartBeatTimeout {
|
|
|
__weak typeof(self) weakself = self;
|
|
__weak typeof(self) weakself = self;
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
|
|
|
|
|
+
|
|
|
UIApplication *application = [UIApplication sharedApplication];
|
|
UIApplication *application = [UIApplication sharedApplication];
|
|
|
UINavigationController *rootVC = (UINavigationController *)application.keyWindow.rootViewController;
|
|
UINavigationController *rootVC = (UINavigationController *)application.keyWindow.rootViewController;
|
|
|
|
|
|
|
|
- // 超时登出
|
|
|
|
|
|
|
+ // 超时登出,登出中停止心跳
|
|
|
[weakself Logout];
|
|
[weakself Logout];
|
|
|
// 提示登录
|
|
// 提示登录
|
|
|
UIViewController* presentVC=rootVC.presentedViewController;
|
|
UIViewController* presentVC=rootVC.presentedViewController;
|
|
@@ -373,14 +393,20 @@
|
|
|
[rootVC popToRootViewControllerAnimated:NO];
|
|
[rootVC popToRootViewControllerAnimated:NO];
|
|
|
RootViewController* topvc= (RootViewController*)rootVC.topViewController;
|
|
RootViewController* topvc= (RootViewController*)rootVC.topViewController;
|
|
|
[topvc dealWithUILogout];
|
|
[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 {
|
|
} else {
|
|
|
// 退回到初始视图
|
|
// 退回到初始视图
|
|
|
[rootVC popToRootViewControllerAnimated:NO];
|
|
[rootVC popToRootViewControllerAnimated:NO];
|
|
|
RootViewController* topvc= (RootViewController*)rootVC.topViewController;
|
|
RootViewController* topvc= (RootViewController*)rootVC.topViewController;
|
|
|
[topvc dealWithUILogout];
|
|
[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];
|
|
[weakself heartBeatTimeout];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- DebugLog(@"heart beat result %d",result);
|
|
|
|
|
|
|
+ NSLog(@"heart beat result %d",result);
|
|
|
|
|
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|