139 lines
4.2 KiB
Objective-C
139 lines
4.2 KiB
Objective-C
//
|
|
// ClientConfig.m
|
|
// YUMI
|
|
//
|
|
// Created by YUMI on 2021/12/11.
|
|
//
|
|
|
|
#import "ClientConfig.h"
|
|
#import "Api+Main.h"
|
|
/// tool
|
|
#import "DESEncrypt.h"
|
|
#import "YUMIConstant.h"
|
|
#import <MJExtension/MJExtension.h>
|
|
#import "XPRoomFaceTool.h"
|
|
#import "NSString+Utils.h"
|
|
#import "YYUtility.h"
|
|
#import "XPWeakTimer.h"
|
|
#import "Api+Main.h"
|
|
|
|
@interface ClientConfig ()
|
|
{
|
|
NSTimer * timer;
|
|
}
|
|
///重试的次数 10次 如果你还是失败的话 那就算了 没办法了
|
|
@property (nonatomic,assign) int retryCount;
|
|
@end
|
|
|
|
@implementation ClientConfig
|
|
|
|
+ (instancetype)shareConfig {
|
|
static dispatch_once_t onceToken;
|
|
static ClientConfig * config;
|
|
dispatch_once(&onceToken, ^{
|
|
config = [[ClientConfig alloc] init];
|
|
});
|
|
return config;
|
|
}
|
|
|
|
- (void)clientInit {
|
|
|
|
#ifdef DEBUG
|
|
self.canOpen = YES;
|
|
#else
|
|
if(isEnterprise == YES){
|
|
self.canOpen = NO;
|
|
}else{
|
|
self.canOpen = YES;
|
|
}
|
|
|
|
#endif
|
|
[Api clientInitConfig:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
|
if (code == 200) {
|
|
self.retryCount = 0;
|
|
NSDictionary * initData = data.data;
|
|
|
|
#ifdef DEBUG
|
|
|
|
self.canOpen = ![initData[@"aModel"] boolValue];
|
|
|
|
#else
|
|
if(isEnterprise == YES){
|
|
self.canOpen = ![initData[@"aModel"] boolValue];
|
|
}else{
|
|
self.canOpen = YES;
|
|
}
|
|
#endif
|
|
|
|
|
|
self.iosPhoneBind = [initData[@"iosPhoneBind"] boolValue];
|
|
//糖果树配置
|
|
self.openCandyTree = [initData[@"openBoxSwitch"] boolValue];
|
|
self.openCandyTreeLimitLevel = [initData[@"openBoxSwitchLevelNo"] intValue];
|
|
ClientDataModel * model = [ClientDataModel modelWithDictionary:data.data];
|
|
self.configInfo = model;
|
|
//表情包
|
|
NSString *json = initData[@"faceJson"][@"json"];
|
|
NSString *deJson = [DESEncrypt decryptUseDES:json key:KeyWithType(KeyType_FacePwdEncode)];
|
|
NSDictionary *faceInitData = [deJson toJSONObject];
|
|
model.faceInitData = faceInitData;
|
|
if (faceInitData) {
|
|
[XPRoomFaceTool shareFaceTool].version = [NSString stringWithFormat:@"%@",faceInitData[@"version"]];
|
|
[XPRoomFaceTool shareFaceTool].zipMd5 = [[NSString stringWithFormat:@"%@",faceInitData[@"zipMd5"]] uppercaseString];
|
|
[XPRoomFaceTool shareFaceTool].zipUrl = [NSString stringWithFormat:@"%@",faceInitData[@"zipUrl"]];
|
|
///表情的数据保存本地
|
|
[[XPRoomFaceTool shareFaceTool] saveFaceInfoList:faceInitData];
|
|
///开始下载
|
|
[[XPRoomFaceTool shareFaceTool] downFaceData];
|
|
}
|
|
NSString *trtcAppId = [NSString stringWithFormat:@"%@",initData[@"trtcAppId"]];
|
|
NSString *curTtcKey = [[NSUserDefaults standardUserDefaults]valueForKey:@"kTrtcAppId"];
|
|
if(curTtcKey == nil){
|
|
if(trtcAppId != nil){
|
|
[[NSUserDefaults standardUserDefaults]setValue:trtcAppId forKey:@"kTrtcAppId"];
|
|
[[NSUserDefaults standardUserDefaults]synchronize];
|
|
}
|
|
}else{
|
|
if(![trtcAppId isEqualToString:curTtcKey]){
|
|
if(trtcAppId != nil){
|
|
[[NSUserDefaults standardUserDefaults]setValue:trtcAppId forKey:@"kTrtcAppId"];
|
|
[[NSUserDefaults standardUserDefaults]synchronize];
|
|
}
|
|
}
|
|
}
|
|
//是否展示公屏
|
|
NSString *serverVer = initData[@"appStoreAuditNoticeVersion"];
|
|
NSString *shortVer = [YYUtility appVersion];
|
|
BOOL isHigh = [NSString versionCompareOldStr:serverVer andNewStr:shortVer];
|
|
model.appStoreAuditNoticeVersion = isHigh;
|
|
self.configInfo = model;
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadnewtab" object:nil];
|
|
} else {
|
|
if (self.retryCount < 10) {
|
|
[self clientInit];
|
|
self.retryCount+=1;
|
|
}
|
|
}
|
|
}];
|
|
}
|
|
|
|
- (void)addHeartBratTimer {
|
|
if (timer) {
|
|
return;
|
|
}
|
|
timer = [XPWeakTimer scheduledTimerWithTimeInterval:30 block:^(id userInfo) {
|
|
[Api requestClientHeartBrat:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
|
|
|
}];
|
|
} userInfo:nil repeats:YES];
|
|
}
|
|
|
|
- (void)resetHeartBratTimer {
|
|
if (timer) {
|
|
timer = nil;
|
|
}
|
|
}
|
|
|
|
|
|
@end
|