123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- //
- // KSLoginManager.m
- // KulexiuForTeacher
- //
- // Created by 王智 on 2023/8/7.
- //
- #import "KSLoginManager.h"
- #import "LoginViewController.h"
- #import "JPUSHService.h"
- #import "CustomNavViewController.h"
- #import "UserInfoManager.h"
- #import "TXIMLinsenter.h"
- #import <KSToolLibrary/UIDevice+TFDevice.h>
- #import "AppDelegate+AppService.h"
- @implementation KSLoginManager
- + (instancetype)shareInstance {
- static KSLoginManager *manager = nil;
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- manager = [[KSLoginManager alloc] init];
- });
- return manager;
- }
- - (instancetype)init {
- self = [super init];
- if (self) {
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(otherLogin) name:@"otherLogin" object:nil];
- }
- return self;
- }
- - (void)otherLogin {
- dispatch_main_async_safe(^{
-
- });
- }
- - (void)loginAction {
-
- }
- - (void)clearUMCount {
- [USER_MANAGER sendUMEvent:@"klx_logout"];
- [USER_MANAGER stopCountUMEvent];
- }
- - (void)logoutAction {
- [[NSNotificationCenter defaultCenter] postNotificationName:@"refreshLiveClickStatus" object:nil];
- [self clearUMCount];
- [KSNetworkingManager clearRequestHeader];
-
- // 取消推送别名
- [JPUSHService deleteAlias:nil seq:0];
- // 退出IM连接
- [TXIM_LINSENTER logoutTXIM];
- USER_MANAGER.hasShowFlash = NO;
- // 清除数据
- [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
- [[NSUserDefaults standardUserDefaults] removeObjectForKey:TokenKey];
- [[NSUserDefaults standardUserDefaults] removeObjectForKey:Token_type];
- [[NSUserDefaults standardUserDefaults] removeObjectForKey:RefreshToken];
- [[NSUserDefaults standardUserDefaults] removeObjectForKey:IM_TOKEN];
- [[NSUserDefaults standardUserDefaults] removeObjectForKey:TENANT_ID];
- // 返回登录页面
- UIViewController *vc = [UIApplication sharedApplication].keyWindow.rootViewController;
- if ([vc isKindOfClass:[UITabBarController class]]) {
- UITabBarController *tab = (UITabBarController *)[UIApplication sharedApplication].keyWindow.rootViewController;
- CustomNavViewController *ctrl = (CustomNavViewController *)tab.selectedViewController;
- [ctrl popToRootViewControllerAnimated:NO];
- LoginViewController *logonVC = [[LoginViewController alloc] init];
- CustomNavViewController *navCtrl = [[CustomNavViewController alloc] initWithRootViewController:logonVC];
- navCtrl.modalPresentationStyle = UIModalPresentationFullScreen;
- [tab.selectedViewController presentViewController:navCtrl animated:YES completion:nil];
-
- // 切换到横屏
- AppDelegate* delegate = [AppDelegate shareAppDelegate];
- [delegate refreshThemeColorAndConfig];
- if (delegate.allowAutoRotate) {
- delegate.allowAutoRotate = NO;
- [UIDevice switchNewOrientation:UIInterfaceOrientationPortrait inController:logonVC];
- }
- }
- else if ([vc isKindOfClass:NSClassFromString(@"CustomNavViewController")]) {
- CustomNavViewController *ctrl = (CustomNavViewController *)vc;
- [ctrl popToRootViewControllerAnimated:YES];
- }
- }
- - (NSString *)getVisableControllerName {
- UIViewController *vc = [AppDelegate shareAppDelegate].window.rootViewController;
- if ([vc isKindOfClass:[UITabBarController class]]) {
- UITabBarController *tab = (UITabBarController *)vc;
- CustomNavViewController *ctrl = (CustomNavViewController *)tab.selectedViewController;
- return NSStringFromClass(ctrl.visibleViewController.class);
- }
- else if ([vc isKindOfClass:[CustomNavViewController class]]) {
- CustomNavViewController *ctrl = (CustomNavViewController *)vc;
- return NSStringFromClass(ctrl.visibleViewController.class);
- }
- else {
- return NSStringFromClass(vc.class);
- }
- }
- @end
|