Files
yingmeng-ios-switf/yinmeng-ios/AppDelegate.swift
2024-03-23 18:21:29 +08:00

78 lines
2.3 KiB
Swift

//
// 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())
}
}