// // AppDelegate.swift // yinmeng-ios // // Created by yinmeng on 2024/1/30. // import UIKit import DeviceKit import NSObject_Rx import NIMSDK @main class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { UIApplication.shared.applicationIconBadgeNumber = 0 self.window = UIWindow.init(frame: UIScreen.main.bounds) self.window?.backgroundColor = UIColor.white self.window?.rootViewController = BaseNavigationViewController(rootViewController:AuthLaunchVC()) loadNIMSDK() loginStateListener() return true } private func loginStateListener() { AuthViewModel.authVM.appClientConfig() ///检车是否已经登录 AuthViewModel.authVM.checkUserIsLogin() AuthViewModel.authVM.loginSuccess.subscribe(onNext: { result in print("是否登录成功\(result)") if result == true { ///如果登录成功显示tabbar self.window?.rootViewController = BaseTabBarViewController() let uid = AuthManager.userUid if uid > 0 { UserViewModel.userVM.getUserInfo(uid: uid) } if NIMSDK.shared().loginManager.isLogined() == false { if let uid = LoginTokenConfig.config.getAccountInfo()?.uid, let token = LoginTokenConfig.config.getAccountInfo()?.netEaseToken { NIMSDK.shared().loginManager.login("\(uid)", token: token) { error in print("aaa") } } else { ///去登录 self.window?.rootViewController = BaseNavigationViewController(rootViewController:AuthLaunchVC()) } } } else { ///去登录 self.window?.rootViewController = BaseNavigationViewController(rootViewController:AuthLaunchVC()) } }).disposed(by: rx.disposeBag) UserViewModel.userVM.selfInfo.subscribe(onNext: { result in if result.nick?.count ?? 0 <= 0 || result.avatar?.count ?? 0 <= 0 { let fillVC = AuthFillDataVC() fillVC.modalPresentationStyle = .fullScreen YMRequestX.topViewController()?.navigationController?.present(fillVC, animated: true) } }).disposed(by: rx.disposeBag) } private func loadNIMSDK() { let opt = NIMSDKOption(appKey: AppKeys.nimAppid) opt.apnsCername = "yinmeng_anps" NIMSDK.shared().register(with: opt) NIMCustomObject.registerCustomDecoder(YinCustomAttachmentCoding()) } }