// // EPNIMManager.m // YuMi // #import "EPNIMManager.h" #import "EPNIMConfig.h" #import #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