Files
real-e-party-iOS/YuMi/E-P/SDKManager/NIMSDK/EPNIMManager.m
edwinQQQ 681b011c99 refactor: 更新 AppDelegate 和模块导入以简化配置管理
主要变更:
1. 移除不必要的模块导入,简化 AppDelegate 中的代码结构。
2. 引入新的 EPConfigManager 和 EPNIMManager,统一配置管理和 NIMSDK 初始化逻辑。
3. 更新相关方法以使用 block 回调,提升代码的可读性和维护性。
4. 新增 EPClientAPIBridge 和相关配置文件,增强项目的模块化。

此更新旨在提升代码的可维护性,减少冗余实现,确保配置管理的一致性。
2025-10-20 18:07:44 +08:00

62 lines
2.0 KiB
Objective-C

//
// EPNIMManager.m
// YuMi
//
#import "EPNIMManager.h"
#import "EPNIMConfig.h"
#import <NIMSDK/NIMSDK.h>
#import "CustomAttachmentDecoder.h"
@interface EPNIMManager ()
@property (nonatomic, assign) BOOL initialized;
@end
@implementation EPNIMManager
+ (instancetype)sharedManager {
static EPNIMManager *s;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{ s = [EPNIMManager new]; });
return s;
}
- (void)initializeWithCompletion:(void(^ _Nullable)(NSError * _Nullable error))completion {
if (self.initialized) {
if (completion) completion(nil);
return;
}
EPNIMConfig *cfg = [EPNIMConfig configFromClientConfig];
if (!cfg) {
if (completion) {
completion([NSError errorWithDomain:@"EPNIM" code:-1001 userInfo:@{NSLocalizedDescriptionKey:@"ClientConfig not ready or nimKey missing"}]);
}
return;
}
NIMSDKOption *option = [NIMSDKOption optionWithAppKey:cfg.appKey];
option.apnsCername = cfg.apnsCername;
[[NIMSDK sharedSDK] registerWithOption:option];
[NIMCustomObject registerCustomDecoder:[[CustomAttachmentDecoder alloc] init]];
[NIMSDKConfig sharedConfig].shouldConsiderRevokedMessageUnreadCount = cfg.shouldConsiderRevokedMessageUnreadCount;
[[NIMSDKConfig sharedConfig] setShouldSyncStickTopSessionInfos:cfg.shouldSyncStickTopSessionInfos];
[NIMSDKConfig sharedConfig].enabledHttpsForInfo = cfg.enabledHttpsForInfo;
[NIMSDKConfig sharedConfig].enabledHttpsForMessage = cfg.enabledHttpsForMessage;
[NIMSDKConfig sharedConfig].cdnTrackInterval = cfg.cdnTrackInterval;
[NIMSDKConfig sharedConfig].chatroomMessageReceiveMinInterval = cfg.chatroomMessageReceiveMinInterval;
self.initialized = YES;
if (completion) completion(nil);
}
- (void)updateApnsToken:(NSData *)deviceToken {
if (!deviceToken) return;
[[NIMSDK sharedSDK] updateApnsToken:deviceToken];
}
- (NSInteger)allUnreadCount { return [NIMSDK sharedSDK].conversationManager.allUnreadCount; }
- (BOOL)isInitialized { return self.initialized; }
@end