KSLoginManager.m 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //
  2. // KSLoginManager.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by 王智 on 2023/8/7.
  6. //
  7. #import "KSLoginManager.h"
  8. #import "LoginViewController.h"
  9. #import "JPUSHService.h"
  10. #import "CustomNavViewController.h"
  11. #import "UserInfoManager.h"
  12. #import "TXIMLinsenter.h"
  13. #import <KSToolLibrary/UIDevice+TFDevice.h>
  14. #import "AppDelegate+AppService.h"
  15. @implementation KSLoginManager
  16. + (instancetype)shareInstance {
  17. static KSLoginManager *manager = nil;
  18. static dispatch_once_t onceToken;
  19. dispatch_once(&onceToken, ^{
  20. manager = [[KSLoginManager alloc] init];
  21. });
  22. return manager;
  23. }
  24. - (instancetype)init {
  25. self = [super init];
  26. if (self) {
  27. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(otherLogin) name:@"otherLogin" object:nil];
  28. }
  29. return self;
  30. }
  31. - (void)otherLogin {
  32. dispatch_main_async_safe(^{
  33. });
  34. }
  35. - (void)loginAction {
  36. }
  37. - (void)clearUMCount {
  38. [USER_MANAGER sendUMEvent:@"klx_logout"];
  39. [USER_MANAGER stopCountUMEvent];
  40. }
  41. - (void)logoutAction {
  42. [[NSNotificationCenter defaultCenter] postNotificationName:@"refreshLiveClickStatus" object:nil];
  43. [self clearUMCount];
  44. [KSNetworkingManager clearRequestHeader];
  45. // 取消推送别名
  46. [JPUSHService deleteAlias:nil seq:0];
  47. // 退出IM连接
  48. [TXIM_LINSENTER logoutTXIM];
  49. USER_MANAGER.hasShowFlash = NO;
  50. // 清除数据
  51. [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
  52. [[NSUserDefaults standardUserDefaults] removeObjectForKey:TokenKey];
  53. [[NSUserDefaults standardUserDefaults] removeObjectForKey:Token_type];
  54. [[NSUserDefaults standardUserDefaults] removeObjectForKey:RefreshToken];
  55. [[NSUserDefaults standardUserDefaults] removeObjectForKey:IM_TOKEN];
  56. [[NSUserDefaults standardUserDefaults] removeObjectForKey:TENANT_ID];
  57. // 返回登录页面
  58. UIViewController *vc = [UIApplication sharedApplication].keyWindow.rootViewController;
  59. if ([vc isKindOfClass:[UITabBarController class]]) {
  60. UITabBarController *tab = (UITabBarController *)[UIApplication sharedApplication].keyWindow.rootViewController;
  61. CustomNavViewController *ctrl = (CustomNavViewController *)tab.selectedViewController;
  62. [ctrl popToRootViewControllerAnimated:NO];
  63. LoginViewController *logonVC = [[LoginViewController alloc] init];
  64. CustomNavViewController *navCtrl = [[CustomNavViewController alloc] initWithRootViewController:logonVC];
  65. navCtrl.modalPresentationStyle = UIModalPresentationFullScreen;
  66. [tab.selectedViewController presentViewController:navCtrl animated:YES completion:nil];
  67. // 切换到横屏
  68. AppDelegate* delegate = [AppDelegate shareAppDelegate];
  69. [delegate refreshThemeColorAndConfig];
  70. if (delegate.allowAutoRotate) {
  71. delegate.allowAutoRotate = NO;
  72. [UIDevice switchNewOrientation:UIInterfaceOrientationPortrait inController:logonVC];
  73. }
  74. }
  75. else if ([vc isKindOfClass:NSClassFromString(@"CustomNavViewController")]) {
  76. CustomNavViewController *ctrl = (CustomNavViewController *)vc;
  77. [ctrl popToRootViewControllerAnimated:YES];
  78. }
  79. }
  80. - (NSString *)getVisableControllerName {
  81. UIViewController *vc = [AppDelegate shareAppDelegate].window.rootViewController;
  82. if ([vc isKindOfClass:[UITabBarController class]]) {
  83. UITabBarController *tab = (UITabBarController *)vc;
  84. CustomNavViewController *ctrl = (CustomNavViewController *)tab.selectedViewController;
  85. return NSStringFromClass(ctrl.visibleViewController.class);
  86. }
  87. else if ([vc isKindOfClass:[CustomNavViewController class]]) {
  88. CustomNavViewController *ctrl = (CustomNavViewController *)vc;
  89. return NSStringFromClass(ctrl.visibleViewController.class);
  90. }
  91. else {
  92. return NSStringFromClass(vc.class);
  93. }
  94. }
  95. @end