79 lines
2.5 KiB
Swift
79 lines
2.5 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: { [weak self] result in
|
|
guard let strongSelf = self else { return }
|
|
|
|
if result == true {
|
|
///如果登录成功显示tabbar
|
|
strongSelf.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("login error: \(String(describing: error))")
|
|
}
|
|
} else {
|
|
strongSelf.showLoginPage()
|
|
}
|
|
}
|
|
} else {
|
|
strongSelf.showLoginPage()
|
|
}
|
|
}).disposed(by: rx.disposeBag)
|
|
|
|
UserViewModel.userVM.selfInfo.subscribe(onNext: { [weak self] result in
|
|
guard let strongSelf = self else { return }
|
|
if result.nick?.count ?? 0 <= 0 || result.avatar?.count ?? 0 <= 0 {
|
|
let fillVC = AuthFillDataVC()
|
|
fillVC.modalPresentationStyle = .fullScreen
|
|
strongSelf.window?.rootViewController = fillVC
|
|
}
|
|
}).disposed(by: rx.disposeBag)
|
|
}
|
|
|
|
private func showLoginPage() {
|
|
self.window?.rootViewController = BaseNavigationViewController(rootViewController:AuthLaunchVC())
|
|
}
|
|
|
|
private func loadNIMSDK() {
|
|
let opt = NIMSDKOption(appKey: AppKeys.nimAppid)
|
|
opt.apnsCername = "yinmeng_anps"
|
|
NIMSDK.shared().register(with: opt)
|
|
NIMCustomObject.registerCustomDecoder(YinCustomAttachmentCoding())
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|