From aa770bc93b5fe54a6a95c04d3783e5d88336bbbe Mon Sep 17 00:00:00 2001 From: zsw666 <1176766775@qq.com> Date: Tue, 10 Dec 2024 15:22:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=99=BB=E5=BD=95=E7=99=BB?= =?UTF-8?q?=E5=87=BA=E4=BD=93=E9=AA=8C=20(#414)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add sample code * update Podfile * v10.4.0 * v10.4.1 * fix NEMapKit.podspec * update Podfile * update NETeamUIKit.podspec * v10.5.0 * 优化登录登出体验 --------- Co-authored-by: 张诗文 --- app.xcodeproj/project.pbxproj | 4 + app/Main/AppDelegate.swift | 58 ++- app/Main/AppKey.swift | 7 +- .../MineSettingViewController.swift | 395 +++++++++--------- .../Controller/NELoginViewController.swift | 210 ++++++++++ 5 files changed, 445 insertions(+), 229 deletions(-) create mode 100644 app/Mine/Controller/NELoginViewController.swift diff --git a/app.xcodeproj/project.pbxproj b/app.xcodeproj/project.pbxproj index 801ba4d0..6dd7076e 100644 --- a/app.xcodeproj/project.pbxproj +++ b/app.xcodeproj/project.pbxproj @@ -40,6 +40,7 @@ 180E81F32D07D9F600151DD8 /* CustomTeamSettingSwitchCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 180E81C22D07D9F600151DD8 /* CustomTeamSettingSwitchCell.swift */; }; 180E81F42D07D9F600151DD8 /* PersonInfoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 180E81B52D07D9F600151DD8 /* PersonInfoViewController.swift */; }; 180E81F52D07D9F600151DD8 /* MeViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 180E81CD2D07D9F600151DD8 /* MeViewModel.swift */; }; + 180E81F72D081DD400151DD8 /* NELoginViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 180E81F62D081DD400151DD8 /* NELoginViewController.swift */; }; 181EE5872B234C510043817F /* CustomView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 181EE57E2B234C510043817F /* CustomView.swift */; }; 181EE5882B234C510043817F /* CustomP2PChatViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 181EE57F2B234C510043817F /* CustomP2PChatViewController.swift */; }; 181EE58B2B234C510043817F /* CustomConversationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 181EE5822B234C510043817F /* CustomConversationController.swift */; }; @@ -117,6 +118,7 @@ 180E81CE2D07D9F600151DD8 /* MineSettingViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MineSettingViewModel.swift; sourceTree = ""; }; 180E81CF2D07D9F600151DD8 /* NodeViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NodeViewModel.swift; sourceTree = ""; }; 180E81D02D07D9F600151DD8 /* PersonInfoViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PersonInfoViewModel.swift; sourceTree = ""; }; + 180E81F62D081DD400151DD8 /* NELoginViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NELoginViewController.swift; sourceTree = ""; }; 181EE57E2B234C510043817F /* CustomView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomView.swift; sourceTree = ""; }; 181EE57F2B234C510043817F /* CustomP2PChatViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomP2PChatViewController.swift; sourceTree = ""; }; 181EE5822B234C510043817F /* CustomConversationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomConversationController.swift; sourceTree = ""; }; @@ -161,6 +163,7 @@ 180E81B82D07D9F600151DD8 /* Controller */ = { isa = PBXGroup; children = ( + 180E81F62D081DD400151DD8 /* NELoginViewController.swift */, 180E81AB2D07D9F600151DD8 /* IMSDKConfigViewController.swift */, 180E81AC2D07D9F600151DD8 /* InputPersonInfoController.swift */, 180E81AD2D07D9F600151DD8 /* IntroduceBrandViewController.swift */, @@ -491,6 +494,7 @@ 180E81E42D07D9F600151DD8 /* NENodeViewController.swift in Sources */, 180E81E52D07D9F600151DD8 /* VersionCell.swift in Sources */, 180E81E62D07D9F600151DD8 /* MessageRemindViewController.swift in Sources */, + 180E81F72D081DD400151DD8 /* NELoginViewController.swift in Sources */, 180E81E72D07D9F600151DD8 /* NEAboutWebViewController.swift in Sources */, 180E81E92D07D9F600151DD8 /* MeViewController.swift in Sources */, 180E81EA2D07D9F600151DD8 /* IMSDKConfigViewController.swift in Sources */, diff --git a/app/Main/AppDelegate.swift b/app/Main/AppDelegate.swift index 9913ba14..db42898d 100644 --- a/app/Main/AppDelegate.swift +++ b/app/Main/AppDelegate.swift @@ -57,37 +57,33 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD NEAIUserManager.shared.setProvider(provider: self) - let account = "<#account#>" - let token = "<#token#>" - loadService() NEKeyboardManager.shared.enable = true NEKeyboardManager.shared.shouldResignOnTouchOutside = true - weak var weakSelf = self - IMKitClient.instance.login(account, token, nil) { error in - if let err = error { - NEALog.infoLog(weakSelf?.className() ?? "", desc: "login IM error : \(err.localizedDescription)") - UIApplication.shared.keyWindow?.makeToast(err.localizedDescription) - // 此处重新登录 - }else { - NEALog.infoLog(weakSelf?.className() ?? "", desc: "login IM Success") - weakSelf?.initConfig() - weakSelf?.initializePage() - } - } + loginWithUI() } @objc func refreshRoot(){ print("refresh root") - // 此处重新登录 + loginWithUI() } @objc func refreshUIStyle(){ initializePage(true) } + func loginWithUI(){ + weak var weakSelf = self + let loginCtrl = NELoginViewController.init() + loginCtrl.successLogin = { + weakSelf?.initConfig() + weakSelf?.initializePage() + } + window?.rootViewController = NENavigationController.init(rootViewController: loginCtrl) + } + func initConfig() { //地图组件初始化 NEMapClient.shared().setupMapClient(withAppkey: AppKey.gaodeMapAppkey, withServerKey: AppKey.gaodeMapServerAppkey) @@ -181,7 +177,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD func loginWithAutoParseConfig(){ guard let json = IMSDKConfigManager.instance.getConfig().customJson else { - // 此处重新登录 + loginWithUI() return } @@ -197,19 +193,19 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD } if let accountId = IMSDKConfigManager.instance.getConfig().accountId, let accountIdToken = IMSDKConfigManager.instance.getConfig().accountIdToken { NEAIUserManager.shared.setProvider(provider: self) - IMKitClient.instance.login(accountId, accountIdToken, nil) { error in + IMKitClient.instance.login(accountId, accountIdToken, nil) { [weak self] error in if let err = error { - NEALog.infoLog(self.className(), desc: "login IM error : \(err.localizedDescription)") + NEALog.infoLog(self?.className() ?? "", desc: "login IM error : \(err.localizedDescription)") UIApplication.shared.keyWindow?.makeToast(err.localizedDescription) - // 此处重新登录 + self?.loginWithUI() } else { - NEALog.infoLog(self.className(), desc: "login IM Success") - self.initConfig() - self.initializePage() + NEALog.infoLog(self?.className() ?? "", desc: "login IM Success") + self?.initConfig() + self?.initializePage() } } } else { - // 此处重新登录 + loginWithUI() } } catch let error { NEALog.infoLog(self.className(), desc: "login poc IM error : \(error.localizedDescription)") @@ -219,19 +215,19 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD func loginWithCustomConfig(){ if let accountId = IMSDKConfigManager.instance.getConfig().accountId, let accountIdToken = IMSDKConfigManager.instance.getConfig().accountIdToken { NEAIUserManager.shared.setProvider(provider: self) - IMKitClient.instance.login(accountId, accountIdToken, nil) { error in + IMKitClient.instance.login(accountId, accountIdToken, nil) { [weak self] error in if let err = error { - NEALog.infoLog(self.className(), desc: "login IM error : \(err.localizedDescription)") + NEALog.infoLog(self?.className() ?? "", desc: "login IM error : \(err.localizedDescription)") UIApplication.shared.keyWindow?.makeToast(err.localizedDescription) - // 此处重新登录 + self?.loginWithUI() } else { - NEALog.infoLog(self.className(), desc: "login IM Success") - self.initConfig() - self.initializePage() + NEALog.infoLog(self?.className() ?? "", desc: "login IM Success") + self?.initConfig() + self?.initializePage() } } } else { - // 此处重新登录 + loginWithUI() } } diff --git a/app/Main/AppKey.swift b/app/Main/AppKey.swift index 00e6e459..4797078c 100644 --- a/app/Main/AppKey.swift +++ b/app/Main/AppKey.swift @@ -3,15 +3,18 @@ // Use of this source code is governed by a MIT license that can be // found in the LICENSE file. +public let account = "<#account#>" +public let token = "<#token#>" + public struct AppKey { #if DEBUG - public static let pushCerName = "<#请输入推送证书#>" public static let appKey = "<#请输入appkey#>" + public static let pushCerName = "<#请输入推送证书#>" public static let gaodeMapAppkey = "<#输入高德地图key#>" public static let gaodeMapServerAppkey = "<#输入高德地图key#>" #else - public static let pushCerName = "<#请输入推送证书#>" public static let appKey = "<#请输入appkey#>" + public static let pushCerName = "<#请输入推送证书#>" public static let gaodeMapAppkey = "<#输入高德地图key#>" public static let gaodeMapServerAppkey = "<#输入高德地图key#>" #endif diff --git a/app/Mine/Controller/MineSettingViewController.swift b/app/Mine/Controller/MineSettingViewController.swift index 2daa9449..cd66387d 100644 --- a/app/Mine/Controller/MineSettingViewController.swift +++ b/app/Mine/Controller/MineSettingViewController.swift @@ -10,125 +10,127 @@ import NIMSDK import UIKit class MineSettingViewController: NEBaseViewController, UITableViewDataSource, UITableViewDelegate { - private var viewModel = MineSettingViewModel() - public var cellClassDic = [ - SettingCellType.SettingArrowCell.rawValue: CustomTeamArrowSettingCell.self, - SettingCellType.SettingSwitchCell.rawValue: CustomTeamSettingSwitchCell.self, - ] - private var tag = "MineSettingViewController" - private let userDefault = UserDefaults.standard - - /// 设置列表 - lazy var tableView: UITableView = { - let tableView = UITableView() - tableView.translatesAutoresizingMaskIntoConstraints = false - tableView.backgroundColor = .clear - tableView.dataSource = self - tableView.delegate = self - tableView.separatorColor = .clear - tableView.separatorStyle = .none - tableView.keyboardDismissMode = .onDrag - - if #available(iOS 11.0, *) { - tableView.estimatedRowHeight = 0 - tableView.estimatedSectionHeaderHeight = 0 - tableView.estimatedSectionFooterHeight = 0 + private var viewModel = MineSettingViewModel() + public var cellClassDic = [ + SettingCellType.SettingArrowCell.rawValue: CustomTeamArrowSettingCell.self, + SettingCellType.SettingSwitchCell.rawValue: CustomTeamSettingSwitchCell.self, + ] + private var tag = "MineSettingViewController" + private let userDefault = UserDefaults.standard + + /// 设置列表 + lazy var tableView: UITableView = { + let tableView = UITableView() + tableView.translatesAutoresizingMaskIntoConstraints = false + tableView.backgroundColor = .clear + tableView.dataSource = self + tableView.delegate = self + tableView.separatorColor = .clear + tableView.separatorStyle = .none + tableView.keyboardDismissMode = .onDrag + + if #available(iOS 11.0, *) { + tableView.estimatedRowHeight = 0 + tableView.estimatedSectionHeaderHeight = 0 + tableView.estimatedSectionFooterHeight = 0 + } + if #available(iOS 15.0, *) { + tableView.sectionHeaderTopPadding = 0.0 + } + return tableView + }() + + /// 退出登录按钮 + let logoutButton = UIButton() + + override func viewDidLoad() { + super.viewDidLoad() + + NotificationCenter.default.addObserver(self, selector: #selector(changeLanguage), name: NENotificationName.changeLanguage, object: nil) + + viewModel.delegate = self + initialConfig() + setupSubviews() + changeLanguage() } - if #available(iOS 15.0, *) { - tableView.sectionHeaderTopPadding = 0.0 + + override func didMove(toParent parent: UIViewController?) { + super.didMove(toParent: parent) + if parent == nil { + NotificationCenter.default.removeObserver(self) + } } - return tableView - }() - - /// 退出登录按钮 - let logoutButton = UIButton() - - override func viewDidLoad() { - super.viewDidLoad() - - NotificationCenter.default.addObserver(self, selector: #selector(changeLanguage), name: NENotificationName.changeLanguage, object: nil) - - viewModel.delegate = self - initialConfig() - setupSubviews() - changeLanguage() - } - - override func didMove(toParent parent: UIViewController?) { - super.didMove(toParent: parent) - if parent == nil { - NotificationCenter.default.removeObserver(self) + + @objc func changeLanguage() { + viewModel.getData() + title = localizable("setting") + tableView.tableFooterView = getFooterView() + tableView.reloadData() } - } - - @objc func changeLanguage() { - viewModel.getData() - title = localizable("setting") - tableView.tableFooterView = getFooterView() - tableView.reloadData() - } - - func initialConfig() { - title = localizable("setting") - - if NEStyleManager.instance.isNormalStyle() { - view.backgroundColor = .ne_backgroundColor - navigationView.backgroundColor = .ne_backgroundColor - navigationController?.navigationBar.backgroundColor = .ne_backgroundColor - } else { - view.backgroundColor = .funChatBackgroundColor - } - } - - func setupSubviews() { - view.addSubview(tableView) - if NEStyleManager.instance.isNormalStyle() { - topConstant += 12 - } - NSLayoutConstraint.activate([ - tableView.leftAnchor.constraint(equalTo: view.leftAnchor), - tableView.rightAnchor.constraint(equalTo: view.rightAnchor), - tableView.topAnchor.constraint(equalTo: view.topAnchor, constant: topConstant), - tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor), - ]) - - for (key, value) in cellClassDic { - tableView.register(value, forCellReuseIdentifier: "\(key)") + + func initialConfig() { + title = localizable("setting") + + if NEStyleManager.instance.isNormalStyle() { + view.backgroundColor = .ne_backgroundColor + navigationView.backgroundColor = .ne_backgroundColor + navigationController?.navigationBar.backgroundColor = .ne_backgroundColor + } else { + view.backgroundColor = .funChatBackgroundColor + } } - - navigationView.moreButton.isHidden = true - } - - func getFooterView() -> UIView? { - let footerView = UIView(frame: CGRect(x: 0, y: 0, width: view.frame.size.width, height: 64.0)) - footerView.addSubview(logoutButton) - logoutButton.backgroundColor = .white - logoutButton.clipsToBounds = true - logoutButton.setTitleColor(UIColor(hexString: "0xE6605C"), for: .normal) - logoutButton.titleLabel?.font = UIFont.systemFont(ofSize: 16) - logoutButton.setTitle(title, for: .normal) - logoutButton.addTarget(self, action: #selector(loginOutAction), for: .touchUpInside) - logoutButton.setTitle(localizable("logout"), for: .normal) - logoutButton.accessibilityIdentifier = "id.logout" - if NEStyleManager.instance.isNormalStyle() { - logoutButton.layer.cornerRadius = 8.0 - logoutButton.frame = CGRect(x: 20, y: 12, width: view.frame.size.width - 40, height: 40) - } else { - logoutButton.translatesAutoresizingMaskIntoConstraints = false - NSLayoutConstraint.activate([ - logoutButton.leftAnchor.constraint(equalTo: footerView.leftAnchor, constant: 0), - logoutButton.rightAnchor.constraint(equalTo: footerView.rightAnchor, constant: 0), - logoutButton.topAnchor.constraint(equalTo: footerView.topAnchor, constant: 12), - logoutButton.heightAnchor.constraint(equalToConstant: 40), - ]) + + func setupSubviews() { + view.addSubview(tableView) + if NEStyleManager.instance.isNormalStyle() { + topConstant += 12 + } + NSLayoutConstraint.activate([ + tableView.leftAnchor.constraint(equalTo: view.leftAnchor), + tableView.rightAnchor.constraint(equalTo: view.rightAnchor), + tableView.topAnchor.constraint(equalTo: view.topAnchor, constant: topConstant), + tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor), + ]) + + for (key, value) in cellClassDic { + tableView.register(value, forCellReuseIdentifier: "\(key)") + } + + navigationView.moreButton.isHidden = true } - - return footerView - } - + + func getFooterView() -> UIView? { + let footerView = UIView(frame: CGRect(x: 0, y: 0, width: view.frame.size.width, height: 64.0)) + footerView.addSubview(logoutButton) + logoutButton.backgroundColor = .white + logoutButton.clipsToBounds = true + logoutButton.setTitleColor(UIColor(hexString: "0xE6605C"), for: .normal) + logoutButton.titleLabel?.font = UIFont.systemFont(ofSize: 16) + logoutButton.setTitle(title, for: .normal) + logoutButton.addTarget(self, action: #selector(loginOutAction), for: .touchUpInside) + logoutButton.setTitle(localizable("logout"), for: .normal) + logoutButton.accessibilityIdentifier = "id.logout" + if NEStyleManager.instance.isNormalStyle() { + logoutButton.layer.cornerRadius = 8.0 + logoutButton.frame = CGRect(x: 20, y: 12, width: view.frame.size.width - 40, height: 40) + } else { + logoutButton.translatesAutoresizingMaskIntoConstraints = false + NSLayoutConstraint.activate([ + logoutButton.leftAnchor.constraint(equalTo: footerView.leftAnchor, constant: 0), + logoutButton.rightAnchor.constraint(equalTo: footerView.rightAnchor, constant: 0), + logoutButton.topAnchor.constraint(equalTo: footerView.topAnchor, constant: 12), + logoutButton.heightAnchor.constraint(equalToConstant: 40), + ]) + } + + return footerView + } + @objc func loginOutAction() { - weak var weakSelf = self - logoutButton.isEnabled = false + weak var weakSelf = self + logoutButton.isEnabled = false + + showAlert(message: localizable("want_to_logout")) { IMKitClient.instance.logoutIM { error in weakSelf?.logoutButton.isEnabled = true if error != nil { @@ -150,93 +152,94 @@ class MineSettingViewController: NEBaseViewController, UITableViewDataSource, UI } } } - - // MARK: UITableViewDataSource, UITableViewDelegate - - func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - if viewModel.sectionData.count > section { - let model = viewModel.sectionData[section] - return model.cellModels.count } - return 0 - } - - func numberOfSections(in tableView: UITableView) -> Int { - viewModel.sectionData.count - } - - func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let model = viewModel.sectionData[indexPath.section].cellModels[indexPath.row] - if let cell = tableView.dequeueReusableCell( - withIdentifier: "\(model.type)", - for: indexPath - ) as? NEBaseTeamSettingCell { - cell.configure(model) - return cell - } - return UITableViewCell() - } - - func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { - let model = viewModel.sectionData[indexPath.section].cellModels[indexPath.row] - if let block = model.cellClick { - block() + + // MARK: UITableViewDataSource, UITableViewDelegate + + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + if viewModel.sectionData.count > section { + let model = viewModel.sectionData[section] + return model.cellModels.count + } + return 0 } - } - - func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { - let model = viewModel.sectionData[indexPath.section].cellModels[indexPath.row] - return model.rowHeight - } - - func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { - if section == 0 { - return 0 - } - if viewModel.sectionData.count > section { - let model = viewModel.sectionData[section] - if model.cellModels.count > 0 { - return 12.0 - } - } - return 0 - } - - func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { - let headerView = UIView() - headerView.backgroundColor = .clear - return headerView - } - - func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { - if section == viewModel.sectionData.count - 1 { - return 12.0 + + func numberOfSections(in tableView: UITableView) -> Int { + viewModel.sectionData.count + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let model = viewModel.sectionData[indexPath.section].cellModels[indexPath.row] + if let cell = tableView.dequeueReusableCell( + withIdentifier: "\(model.type)", + for: indexPath + ) as? NEBaseTeamSettingCell { + cell.configure(model) + return cell + } + return UITableViewCell() + } + + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + let model = viewModel.sectionData[indexPath.section].cellModels[indexPath.row] + if let block = model.cellClick { + block() + } + } + + func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { + let model = viewModel.sectionData[indexPath.section].cellModels[indexPath.row] + return model.rowHeight + } + + func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { + if section == 0 { + return 0 + } + if viewModel.sectionData.count > section { + let model = viewModel.sectionData[section] + if model.cellModels.count > 0 { + return 12.0 + } + } + return 0 + } + + func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { + let headerView = UIView() + headerView.backgroundColor = .clear + return headerView + } + + func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { + if section == viewModel.sectionData.count - 1 { + return 12.0 + } + return 0 } - return 0 - } } extension MineSettingViewController: MineSettingViewModelDelegate { - func didMessageRemindClick() { - let messageRemindCtrl = MessageRemindViewController() - navigationController?.pushViewController(messageRemindCtrl, animated: true) - } - - func didStyleClick() { - let styleSelectionCtrl = StyleSelectionViewController() - navigationController?.pushViewController(styleSelectionCtrl, animated: true) - } - - func didClickCleanCache() {} - - - func didClickSDKConfig() { - let configController = IMSDKConfigViewController() - navigationController?.pushViewController(configController, animated: true) - } - - func didClickLanguage() { - let configController = LanguageViewController() - navigationController?.pushViewController(configController, animated: true) - } + func didMessageRemindClick() { + let messageRemindCtrl = MessageRemindViewController() + navigationController?.pushViewController(messageRemindCtrl, animated: true) + } + + func didStyleClick() { + let styleSelectionCtrl = StyleSelectionViewController() + navigationController?.pushViewController(styleSelectionCtrl, animated: true) + } + + func didClickCleanCache() {} + + + func didClickSDKConfig() { + let configController = IMSDKConfigViewController() + navigationController?.pushViewController(configController, animated: true) + } + + func didClickLanguage() { + let configController = LanguageViewController() + navigationController?.pushViewController(configController, animated: true) + } } diff --git a/app/Mine/Controller/NELoginViewController.swift b/app/Mine/Controller/NELoginViewController.swift new file mode 100644 index 00000000..de0ed226 --- /dev/null +++ b/app/Mine/Controller/NELoginViewController.swift @@ -0,0 +1,210 @@ +// Copyright (c) 2022 NetEase, Inc. All rights reserved. +// Use of this source code is governed by a MIT license that can be +// found in the LICENSE file. + +import NEChatUIKit +import NECommonKit +import NECoreIM2Kit +import NIMSDK +import UIKit + +@objcMembers +public class NELoginViewController: UIViewController { + // 登录成功 + public typealias LoginBlock = () -> Void + + public var successLogin: LoginBlock? + + lazy var launchIconView: UIImageView = { + let imageView = UIImageView() + imageView.translatesAutoresizingMaskIntoConstraints = false + imageView.image = UIImage(named: "launchIcon") + return imageView + }() + + lazy var launchIconLabel: UILabel = { + let label = UILabel() + label.translatesAutoresizingMaskIntoConstraints = false + label.text = localizable("appName") + label.font = UIFont.systemFont(ofSize: 24.0) + label.textColor = UIColor(hexString: "333333") + label.accessibilityIdentifier = "id.appYunxin" + return label + }() + + lazy var loginButton: UIButton = { + let button = UIButton() + button.translatesAutoresizingMaskIntoConstraints = false + button.layer.cornerRadius = 8 + button.backgroundColor = UIColor.ne_normalTheme + button.setTitleColor(UIColor.white, for: .normal) + button.titleLabel?.font = UIFont.systemFont(ofSize: 15.0) + button.setTitle(localizable("register_login"), for: .normal) + button.addTarget(self, action: #selector(loginBtnClick), for: .touchUpInside) + button.accessibilityIdentifier = "id.loginButton" + return button + }() + + lazy var emailLoginButton: UIButton = { + let button = UIButton() + button.frame = CGRect(x: 0, y: 0, width: 60, height: 44) + button.setTitleColor(UIColor.ne_lightText, for: .normal) + button.titleLabel?.font = UIFont.systemFont(ofSize: 12.0) + button.setTitle(localizable("email_login"), for: .normal) + button.addTarget(self, action: #selector(emailLoginBtnClick), for: .touchUpInside) + button.accessibilityIdentifier = "id.emailLogin" + return button + }() + + lazy var dividerLineView: UIView = { + let view = UIView() + view.translatesAutoresizingMaskIntoConstraints = false + view.backgroundColor = UIColor.ne_lightText + return view + }() + + /// 节点按钮 + lazy var nodeButton: UIButton = { + let button = UIButton() + button.frame = CGRect(x: 0, y: 0, width: 60, height: 44) + button.setTitleColor(UIColor.ne_lightText, for: .normal) + button.titleLabel?.font = UIFont.systemFont(ofSize: 12.0) + button.setTitle(localizable("node_select"), for: .normal) + button.addTarget(self, action: #selector(nodeBtnClick), for: .touchUpInside) + button.accessibilityIdentifier = "id.serverConfig" + return button + }() + + /// poc 登录 + lazy var pocLoginButton: UIButton = { + let button = UIButton() + button.frame = CGRect(x: 0, y: 0, width: 60, height: 44) + button.setTitleColor(UIColor.ne_lightText, for: .normal) + button.titleLabel?.font = UIFont.systemFont(ofSize: 12.0) + button.setTitle(localizable("login_by_account"), for: .normal) + button.addTarget(self, action: #selector(pocLoginBtnClick), for: .touchUpInside) + button.accessibilityIdentifier = "id.pocLogin" + return button + }() + + /// poc 配置 + lazy var pocSettingButton: UIButton = { + let button = UIButton() + button.frame = CGRect(x: 0, y: 0, width: 60, height: 44) + button.setTitleColor(UIColor.ne_lightText, for: .normal) + button.titleLabel?.font = UIFont.systemFont(ofSize: 12.0) + button.setTitle(localizable("privatized_configuration"), for: .normal) + button.addTarget(self, action: #selector(pocSettingBtnClick), for: .touchUpInside) + button.accessibilityIdentifier = "id.pocSetting" + return button + }() + + override public func viewDidLoad() { + super.viewDidLoad() + setupUI() + } + + override public func viewWillAppear(_ animated: Bool) { + navigationController?.navigationBar.isHidden = true + } + + override public func viewWillDisappear(_ animated: Bool) { + navigationController?.navigationBar.isHidden = false + } + + func setupUI() { + view.addSubview(launchIconView) + view.addSubview(launchIconLabel) + view.addSubview(loginButton) + view.addSubview(emailLoginButton) + view.addSubview(dividerLineView) + view.addSubview(nodeButton) + + if #available(iOS 11.0, *) { + NSLayoutConstraint.activate([ + launchIconView.centerXAnchor.constraint(equalTo: view.centerXAnchor), + launchIconView.topAnchor.constraint( + equalTo: view.safeAreaLayoutGuide.topAnchor, + constant: 145.0 + ), + ]) + } else { + NSLayoutConstraint.activate([ + launchIconView.centerXAnchor.constraint(equalTo: view.centerXAnchor), + launchIconView.topAnchor.constraint(equalTo: view.topAnchor, constant: 145.0), + ]) + } + NSLayoutConstraint.activate([ + launchIconLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor), + launchIconLabel.topAnchor.constraint(equalTo: launchIconView.bottomAnchor, constant: -12.0), + ]) + + NSLayoutConstraint.activate([ + loginButton.centerXAnchor.constraint(equalTo: view.centerXAnchor), + loginButton.topAnchor.constraint(equalTo: launchIconLabel.bottomAnchor, constant: 20), + loginButton.widthAnchor.constraint(equalToConstant: NEConstant.screenWidth - 80), + loginButton.heightAnchor.constraint(equalToConstant: 44), + ]) + + let stackView = UIStackView() + stackView.translatesAutoresizingMaskIntoConstraints = false + stackView.axis = .horizontal + stackView.alignment = .center + stackView.distribution = .fillEqually + stackView.spacing = 8 + stackView.addArrangedSubview(emailLoginButton) + stackView.addArrangedSubview(nodeButton) + stackView.addArrangedSubview(pocSettingButton) + stackView.addArrangedSubview(pocLoginButton) + + view.addSubview(stackView) + NSLayoutConstraint.activate([ + stackView.centerXAnchor.constraint(equalTo: view.centerXAnchor), + stackView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -60), + stackView.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 20), + stackView.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -20), + stackView.heightAnchor.constraint(equalToConstant: 44), + ]) + } + + func loginBtnClick(sender: UIButton) { + weak var weakSelf = self + print("login accid : ", account) + print("login token : ", token) + + let option = V2NIMLoginOption() + IMKitClient.instance.login(account, token, option) { error in + if let err = error { + NEALog.infoLog(weakSelf?.className() ?? "", desc: "login IM error : \(err.localizedDescription)") + UIApplication.shared.keyWindow?.makeToast(err.localizedDescription) + } else { + NEALog.infoLog(weakSelf?.className() ?? "", desc: "login IM Success") + if let block = weakSelf?.successLogin { + block() + } + } + } + } + + func emailLoginBtnClick(sender: UIButton) { + + } + + func nodeBtnClick(sender: UIButton) { + let ctrl = NENodeViewController() + navigationController?.pushViewController(ctrl, animated: true) + } + + func pocLoginBtnClick(sender: UIButton) { + let ctrl = PocLoginController() + ctrl.loginSuccess = { [weak self] in + self?.successLogin?() + } + navigationController?.pushViewController(ctrl, animated: true) + } + + func pocSettingBtnClick(sender: UIButton) { + let configeController = IMSDKConfigViewController() + navigationController?.pushViewController(configeController, animated: true) + } +}