Skip to content

Commit aa770bc

Browse files
zsw666张诗文
andauthored
优化登录登出体验 (#414)
* 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]>
1 parent 13783d0 commit aa770bc

File tree

5 files changed

+445
-229
lines changed

5 files changed

+445
-229
lines changed

app.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
180E81F32D07D9F600151DD8 /* CustomTeamSettingSwitchCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 180E81C22D07D9F600151DD8 /* CustomTeamSettingSwitchCell.swift */; };
4141
180E81F42D07D9F600151DD8 /* PersonInfoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 180E81B52D07D9F600151DD8 /* PersonInfoViewController.swift */; };
4242
180E81F52D07D9F600151DD8 /* MeViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 180E81CD2D07D9F600151DD8 /* MeViewModel.swift */; };
43+
180E81F72D081DD400151DD8 /* NELoginViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 180E81F62D081DD400151DD8 /* NELoginViewController.swift */; };
4344
181EE5872B234C510043817F /* CustomView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 181EE57E2B234C510043817F /* CustomView.swift */; };
4445
181EE5882B234C510043817F /* CustomP2PChatViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 181EE57F2B234C510043817F /* CustomP2PChatViewController.swift */; };
4546
181EE58B2B234C510043817F /* CustomConversationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 181EE5822B234C510043817F /* CustomConversationController.swift */; };
@@ -117,6 +118,7 @@
117118
180E81CE2D07D9F600151DD8 /* MineSettingViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MineSettingViewModel.swift; sourceTree = "<group>"; };
118119
180E81CF2D07D9F600151DD8 /* NodeViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NodeViewModel.swift; sourceTree = "<group>"; };
119120
180E81D02D07D9F600151DD8 /* PersonInfoViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PersonInfoViewModel.swift; sourceTree = "<group>"; };
121+
180E81F62D081DD400151DD8 /* NELoginViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NELoginViewController.swift; sourceTree = "<group>"; };
120122
181EE57E2B234C510043817F /* CustomView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomView.swift; sourceTree = "<group>"; };
121123
181EE57F2B234C510043817F /* CustomP2PChatViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomP2PChatViewController.swift; sourceTree = "<group>"; };
122124
181EE5822B234C510043817F /* CustomConversationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomConversationController.swift; sourceTree = "<group>"; };
@@ -161,6 +163,7 @@
161163
180E81B82D07D9F600151DD8 /* Controller */ = {
162164
isa = PBXGroup;
163165
children = (
166+
180E81F62D081DD400151DD8 /* NELoginViewController.swift */,
164167
180E81AB2D07D9F600151DD8 /* IMSDKConfigViewController.swift */,
165168
180E81AC2D07D9F600151DD8 /* InputPersonInfoController.swift */,
166169
180E81AD2D07D9F600151DD8 /* IntroduceBrandViewController.swift */,
@@ -491,6 +494,7 @@
491494
180E81E42D07D9F600151DD8 /* NENodeViewController.swift in Sources */,
492495
180E81E52D07D9F600151DD8 /* VersionCell.swift in Sources */,
493496
180E81E62D07D9F600151DD8 /* MessageRemindViewController.swift in Sources */,
497+
180E81F72D081DD400151DD8 /* NELoginViewController.swift in Sources */,
494498
180E81E72D07D9F600151DD8 /* NEAboutWebViewController.swift in Sources */,
495499
180E81E92D07D9F600151DD8 /* MeViewController.swift in Sources */,
496500
180E81EA2D07D9F600151DD8 /* IMSDKConfigViewController.swift in Sources */,

app/Main/AppDelegate.swift

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -57,37 +57,33 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
5757

5858
NEAIUserManager.shared.setProvider(provider: self)
5959

60-
let account = "<#account#>"
61-
let token = "<#token#>"
62-
6360
loadService()
6461
NEKeyboardManager.shared.enable = true
6562
NEKeyboardManager.shared.shouldResignOnTouchOutside = true
6663

67-
weak var weakSelf = self
68-
IMKitClient.instance.login(account, token, nil) { error in
69-
if let err = error {
70-
NEALog.infoLog(weakSelf?.className() ?? "", desc: "login IM error : \(err.localizedDescription)")
71-
UIApplication.shared.keyWindow?.makeToast(err.localizedDescription)
72-
// 此处重新登录
73-
}else {
74-
NEALog.infoLog(weakSelf?.className() ?? "", desc: "login IM Success")
75-
weakSelf?.initConfig()
76-
weakSelf?.initializePage()
77-
}
78-
}
64+
loginWithUI()
7965

8066
}
8167

8268
@objc func refreshRoot(){
8369
print("refresh root")
84-
// 此处重新登录
70+
loginWithUI()
8571
}
8672

8773
@objc func refreshUIStyle(){
8874
initializePage(true)
8975
}
9076

77+
func loginWithUI(){
78+
weak var weakSelf = self
79+
let loginCtrl = NELoginViewController.init()
80+
loginCtrl.successLogin = {
81+
weakSelf?.initConfig()
82+
weakSelf?.initializePage()
83+
}
84+
window?.rootViewController = NENavigationController.init(rootViewController: loginCtrl)
85+
}
86+
9187
func initConfig() {
9288
//地图组件初始化
9389
NEMapClient.shared().setupMapClient(withAppkey: AppKey.gaodeMapAppkey, withServerKey: AppKey.gaodeMapServerAppkey)
@@ -181,7 +177,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
181177
func loginWithAutoParseConfig(){
182178

183179
guard let json = IMSDKConfigManager.instance.getConfig().customJson else {
184-
// 此处重新登录
180+
loginWithUI()
185181
return
186182
}
187183

@@ -197,19 +193,19 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
197193
}
198194
if let accountId = IMSDKConfigManager.instance.getConfig().accountId, let accountIdToken = IMSDKConfigManager.instance.getConfig().accountIdToken {
199195
NEAIUserManager.shared.setProvider(provider: self)
200-
IMKitClient.instance.login(accountId, accountIdToken, nil) { error in
196+
IMKitClient.instance.login(accountId, accountIdToken, nil) { [weak self] error in
201197
if let err = error {
202-
NEALog.infoLog(self.className(), desc: "login IM error : \(err.localizedDescription)")
198+
NEALog.infoLog(self?.className() ?? "", desc: "login IM error : \(err.localizedDescription)")
203199
UIApplication.shared.keyWindow?.makeToast(err.localizedDescription)
204-
// 此处重新登录
200+
self?.loginWithUI()
205201
} else {
206-
NEALog.infoLog(self.className(), desc: "login IM Success")
207-
self.initConfig()
208-
self.initializePage()
202+
NEALog.infoLog(self?.className() ?? "", desc: "login IM Success")
203+
self?.initConfig()
204+
self?.initializePage()
209205
}
210206
}
211207
} else {
212-
// 此处重新登录
208+
loginWithUI()
213209
}
214210
} catch let error {
215211
NEALog.infoLog(self.className(), desc: "login poc IM error : \(error.localizedDescription)")
@@ -219,19 +215,19 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
219215
func loginWithCustomConfig(){
220216
if let accountId = IMSDKConfigManager.instance.getConfig().accountId, let accountIdToken = IMSDKConfigManager.instance.getConfig().accountIdToken {
221217
NEAIUserManager.shared.setProvider(provider: self)
222-
IMKitClient.instance.login(accountId, accountIdToken, nil) { error in
218+
IMKitClient.instance.login(accountId, accountIdToken, nil) { [weak self] error in
223219
if let err = error {
224-
NEALog.infoLog(self.className(), desc: "login IM error : \(err.localizedDescription)")
220+
NEALog.infoLog(self?.className() ?? "", desc: "login IM error : \(err.localizedDescription)")
225221
UIApplication.shared.keyWindow?.makeToast(err.localizedDescription)
226-
// 此处重新登录
222+
self?.loginWithUI()
227223
} else {
228-
NEALog.infoLog(self.className(), desc: "login IM Success")
229-
self.initConfig()
230-
self.initializePage()
224+
NEALog.infoLog(self?.className() ?? "", desc: "login IM Success")
225+
self?.initConfig()
226+
self?.initializePage()
231227
}
232228
}
233229
} else {
234-
// 此处重新登录
230+
loginWithUI()
235231
}
236232
}
237233

app/Main/AppKey.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@
33
// Use of this source code is governed by a MIT license that can be
44
// found in the LICENSE file.
55

6+
public let account = "<#account#>"
7+
public let token = "<#token#>"
8+
69
public struct AppKey {
710
#if DEBUG
8-
public static let pushCerName = "<#请输入推送证书#>"
911
public static let appKey = "<#请输入appkey#>"
12+
public static let pushCerName = "<#请输入推送证书#>"
1013
public static let gaodeMapAppkey = "<#输入高德地图key#>"
1114
public static let gaodeMapServerAppkey = "<#输入高德地图key#>"
1215
#else
13-
public static let pushCerName = "<#请输入推送证书#>"
1416
public static let appKey = "<#请输入appkey#>"
17+
public static let pushCerName = "<#请输入推送证书#>"
1518
public static let gaodeMapAppkey = "<#输入高德地图key#>"
1619
public static let gaodeMapServerAppkey = "<#输入高德地图key#>"
1720
#endif

0 commit comments

Comments
 (0)