Skip to content

Commit

Permalink
优化登录登出体验 (#414)
Browse files Browse the repository at this point in the history
* 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: 张诗文 <[email protected]>
  • Loading branch information
zsw666 and 张诗文 authored Dec 10, 2024
1 parent 13783d0 commit aa770bc
Show file tree
Hide file tree
Showing 5 changed files with 445 additions and 229 deletions.
4 changes: 4 additions & 0 deletions app.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -117,6 +118,7 @@
180E81CE2D07D9F600151DD8 /* MineSettingViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MineSettingViewModel.swift; sourceTree = "<group>"; };
180E81CF2D07D9F600151DD8 /* NodeViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NodeViewModel.swift; sourceTree = "<group>"; };
180E81D02D07D9F600151DD8 /* PersonInfoViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PersonInfoViewModel.swift; sourceTree = "<group>"; };
180E81F62D081DD400151DD8 /* NELoginViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NELoginViewController.swift; sourceTree = "<group>"; };
181EE57E2B234C510043817F /* CustomView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomView.swift; sourceTree = "<group>"; };
181EE57F2B234C510043817F /* CustomP2PChatViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomP2PChatViewController.swift; sourceTree = "<group>"; };
181EE5822B234C510043817F /* CustomConversationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomConversationController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -161,6 +163,7 @@
180E81B82D07D9F600151DD8 /* Controller */ = {
isa = PBXGroup;
children = (
180E81F62D081DD400151DD8 /* NELoginViewController.swift */,
180E81AB2D07D9F600151DD8 /* IMSDKConfigViewController.swift */,
180E81AC2D07D9F600151DD8 /* InputPersonInfoController.swift */,
180E81AD2D07D9F600151DD8 /* IntroduceBrandViewController.swift */,
Expand Down Expand Up @@ -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 */,
Expand Down
58 changes: 27 additions & 31 deletions app/Main/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -181,7 +177,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
func loginWithAutoParseConfig(){

guard let json = IMSDKConfigManager.instance.getConfig().customJson else {
// 此处重新登录
loginWithUI()
return
}

Expand All @@ -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)")
Expand All @@ -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()
}
}

Expand Down
7 changes: 5 additions & 2 deletions app/Main/AppKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit aa770bc

Please sign in to comment.