@@ -28,44 +28,44 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
2828 registerAPNS ( )
2929 return true
3030 }
31-
31+
32+ func setupIM( _ appkey: String ? = nil ) {
33+ // 设置IM SDK的配置项,包括AppKey,推送配置和一些全局配置等
34+ let option = NIMSDKOption ( )
35+ option. appKey = appkey ?? AppKey . appKey
36+ option. apnsCername = AppKey . apnsCername
37+ option. pkCername = AppKey . pkCerName
38+
39+ // 设置IM SDK V2的配置项,包括是否使用旧的登录接口和是否使用云端会话
40+ let v2Option = V2NIMSDKOption ( )
41+ v2Option. enableV2CloudConversation = ( UserDefaults . standard. value ( forKey: keyEnableCloudConversation) as? Bool ) ?? false
42+
43+ // 初始化IM UIKit,初始化Kit层和IM SDK,将配置信息透传给IM SDK。无需再次初始化IM SDK
44+ IMKitClient . instance. setupIM2 ( option, v2Option)
45+ }
46+
3247 func setupInit( ) {
3348 if IMSDKConfigManager . instance. getConfig ( ) . enableCustomConfig. boolValue {
3449 // 开启自定义配置,使用自定义配置
3550// NIMSDK.shared().serverSetting = NIMServerSetting()
36-
51+
3752 if IMSDKConfigManager . instance. getConfig ( ) . customJson? . count ?? 0 > 0 {
3853 loginWithAutoParseConfig ( )
3954 return
4055 } else if let appkey = IMSDKConfigManager . instance. getConfig ( ) . configMap [ #keyPath( NIMSDKOption . appKey) ] as? String {
41- let option = NIMSDKOption ( )
42- option. v2 = true
43- option. appKey = appkey
44- IMKitClient . instance. setupIM ( option)
56+ setupIM ( appkey)
4557 loginWithCustomConfig ( )
4658 return
4759 }
4860 }
49-
50- // 设置IM SDK的配置项,包括AppKey,推送配置和一些全局配置等
51- let option = NIMSDKOption ( )
52- option. appKey = AppKey . appKey
53- option. apnsCername = AppKey . apnsCername
54- option. pkCername = AppKey . pkCerName
55-
56- // 设置IM SDK V2的配置项,包括是否使用旧的登录接口和是否使用云端会话
57- let v2Option = V2NIMSDKOption ( )
58- v2Option. enableV2CloudConversation = ( UserDefaults . standard. value ( forKey: keyEnableCloudConversation) as? Bool ) ?? false
5961
60- // 初始化IM UIKit,初始化Kit层和IM SDK,将配置信息透传给IM SDK。无需再次初始化IM SDK
61- IMKitClient . instance. setupIM2 ( option, v2Option)
62-
63- NEAIUserManager . shared. setProvider ( provider: self )
64- NEKeyboardManager . shared. enable = true
65- NEKeyboardManager . shared. shouldResignOnTouchOutside = true
66-
62+ setupIM ( )
6763 loadService ( )
6864 loginWithUI ( )
65+
66+ NEAIUserManager . shared. setProvider ( provider: self )
67+ NEKeyboardManager . shared. enable = true
68+ NEKeyboardManager . shared. shouldResignOnTouchOutside = true
6969 }
7070
7171 @objc func refreshRoot( ) {
@@ -196,14 +196,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
196196 let jsonData = json. data ( using: . utf8) ?? Data ( )
197197 do {
198198 let dict = try JSONSerialization . jsonObject ( with: jsonData, options: . mutableContainers) as? [ String : Any ]
199- let option = NIMSDKOption ( )
200- option. v2 = true
201- if let appkey = dict ? [ " appkey " ] as? String {
202- option. v2 = true
203- option. appKey = appkey
204- IMKitClient . instance. setupIM ( option)
205- }
206- if let accountId = IMSDKConfigManager . instance. getConfig ( ) . accountId, let accountIdToken = IMSDKConfigManager . instance. getConfig ( ) . accountIdToken {
199+ let appkey = dict ? [ " appkey " ] as? String
200+ setupIM ( appkey)
201+
202+ if let accountId = IMSDKConfigManager . instance. getConfig ( ) . accountId,
203+ let accountIdToken = IMSDKConfigManager . instance. getConfig ( ) . accountIdToken {
207204 NEAIUserManager . shared. setProvider ( provider: self )
208205 IMKitClient . instance. login ( accountId, accountIdToken, nil ) { [ weak self] error in
209206 if let err = error {
0 commit comments