278 lines
9.7 KiB
Objective-C
278 lines
9.7 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"
|
||
#import "ChatFaceVo.h"
|
||
#import "PublicRoomManager.h"
|
||
|
||
@interface ClientConfig ()
|
||
///重试的次数 10次 如果你还是失败的话 那就算了 没办法了
|
||
@property (nonatomic,assign) int retryCount;
|
||
|
||
@property (nonatomic, strong) NSMutableArray *normalTabImageSource;
|
||
@property (nonatomic, strong) NSMutableArray *selectedTabImageSource;
|
||
@property (nonatomic, strong) NetImageView *normalTabImageLoader;
|
||
@property (nonatomic, strong) NetImageView *selectedTabImageLoader;
|
||
@property (nonatomic, strong) NetImageView *tabbarBGImageLoader;
|
||
@property (nonatomic, strong) NetImageView *navigationAreaBGImageLoader;
|
||
|
||
@property (nonatomic, assign) BOOL isLoading;
|
||
|
||
@end
|
||
|
||
@implementation ClientConfig
|
||
|
||
+ (instancetype)shareConfig {
|
||
static dispatch_once_t onceToken;
|
||
static ClientConfig * config;
|
||
dispatch_once(&onceToken, ^{
|
||
config = [[ClientConfig alloc] init];
|
||
config.isTF = [ClientConfig isTestFlight];
|
||
config.reloadNavigationAreaImageKey = @"今天光线很好";
|
||
config.reloadViewBackgroundColorKey = @"年轻人买不起:美国买房平均年龄飙升至56岁";
|
||
});
|
||
return config;
|
||
}
|
||
|
||
+(BOOL)isTestFlight{
|
||
NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
|
||
NSString *receiptURLString = [receiptURL path];
|
||
BOOL isTestFlight = ([receiptURLString containsString:@"sandboxReceipt"] || [receiptURLString containsString:@"_MASReceipt/receipt"]);
|
||
return isTestFlight;
|
||
}
|
||
|
||
- (void)clientInit {
|
||
@kWeakify(self);
|
||
[Api clientInitConfig:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
||
@kStrongify(self);
|
||
if (code == 200) {
|
||
self.retryCount = 0;
|
||
|
||
ClientDataModel * model = [ClientDataModel modelWithDictionary:data.data];
|
||
|
||
self.iOSPhoneBind = model.iosPhoneBind;
|
||
|
||
//糖果树配置
|
||
self.openCandyTree = model.openBoxSwitch;
|
||
self.openCandyTreeLimitLevel = model.openBoxSwitchLevelNo;
|
||
|
||
//表情包
|
||
NSString *json = model.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 = @(model.trtcAppId).stringValue;
|
||
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 = model.appStoreAuditNoticeVersion;
|
||
NSString *shortVer = [YYUtility appVersion];
|
||
model.hideNoticeVersion = [NSString versionCompareOldStr:serverVer andNewStr:shortVer];
|
||
|
||
self.configInfo = model;
|
||
|
||
// 通知公共房间管理器配置已更新
|
||
[[PublicRoomManager sharedManager] updateConfig];
|
||
|
||
[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadAfterLoadConfig" object:nil];
|
||
|
||
[self requestFaceTabNewList];
|
||
} else {
|
||
if (self.retryCount < 10) {
|
||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||
self.retryCount+=1;
|
||
[self clientInit];
|
||
});
|
||
}
|
||
}
|
||
}];
|
||
}
|
||
|
||
- (void)requestFaceTabNewList {
|
||
[Api faceTabNewList:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
||
if (code == 200) {
|
||
[[XPRoomFaceTool shareFaceTool] cacheChatFaces:data.data];
|
||
}
|
||
}];
|
||
}
|
||
|
||
- (void)clientConfig:(void(^)(void))finish {
|
||
@kWeakify(self);
|
||
[Api clientConfig:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
||
@kStrongify(self);
|
||
if (code == 200) {
|
||
self.uiSetting = [AppUISetting modelWithJSON:data.data[@"appUiSetting"]];
|
||
}
|
||
// 无论如何都开始构建 tab image path 数组并进入首页
|
||
[self prepareCustomUI];
|
||
if (finish) {
|
||
finish();
|
||
}
|
||
}];
|
||
}
|
||
|
||
- (void)prepareCustomUI {
|
||
NSArray *defaultArray = @[@"", @"", @"", @"", @""];
|
||
self.normalTabImageSource = defaultArray.mutableCopy;
|
||
self.selectedTabImageSource = defaultArray.mutableCopy;
|
||
|
||
if (self.uiSetting) {
|
||
NSArray *unselectIcons = @[
|
||
self.uiSetting.homeUnSelectIcon ?: @"",
|
||
self.uiSetting.gameUnSelectIcon ?: @"",
|
||
self.uiSetting.dynamicUnSelectIcon ?: @"",
|
||
self.uiSetting.msgUnSelectIcon ?: @"",
|
||
self.uiSetting.mineUnSelectIcon ?: @""
|
||
];
|
||
|
||
NSArray *selectIcons = @[
|
||
self.uiSetting.homeSelectIcon ?: @"",
|
||
self.uiSetting.gameSelectIcon ?: @"",
|
||
self.uiSetting.dynamicSelectIcon ?: @"",
|
||
self.uiSetting.msgSelectIcon ?: @"",
|
||
self.uiSetting.mineSelectIcon ?: @""
|
||
];
|
||
|
||
self.normalTabImageSource = unselectIcons.mutableCopy;
|
||
self.selectedTabImageSource = selectIcons.mutableCopy;
|
||
|
||
[self loadNavigationAreaBG];
|
||
[self loadTabbarBG];
|
||
[self loadBGColor];
|
||
} else {
|
||
if (self.updateTabbarBG) {
|
||
self.updateTabbarBG(kImage(@"tab_bar_bg"));
|
||
}
|
||
}
|
||
}
|
||
|
||
- (UIImage *)navigationAreaBG {
|
||
if (!_navigationAreaBG) {
|
||
return kImage(@"home_top_bg");
|
||
} else {
|
||
return _navigationAreaBG;
|
||
}
|
||
}
|
||
|
||
- (void)loadNavigationAreaBG {
|
||
if (!_navigationAreaBGImageLoader) {
|
||
_navigationAreaBGImageLoader = [[NetImageView alloc] init];
|
||
}
|
||
|
||
@kWeakify(self);
|
||
[self.navigationAreaBGImageLoader loadImageWithUrl:self.uiSetting.headIcon
|
||
completion:^(UIImage * _Nullable image, NSURL * _Nonnull url) {
|
||
@kStrongify(self);
|
||
self.navigationAreaBG = image;
|
||
[[NSNotificationCenter defaultCenter] postNotificationName:self.reloadNavigationAreaImageKey object:[image resizeTo:CGSizeMake(1125, 420)]];
|
||
} fail:^(NSError * _Nonnull error) {}];
|
||
}
|
||
|
||
- (void)loadTabbarBG {
|
||
|
||
if (!_tabbarBGImageLoader) {
|
||
_tabbarBGImageLoader = [[NetImageView alloc] init];
|
||
}
|
||
|
||
@kWeakify(self);
|
||
[self.tabbarBGImageLoader loadImageWithUrl:self.uiSetting.navbar
|
||
completion:^(UIImage * _Nullable image, NSURL * _Nonnull url) {
|
||
@kStrongify(self);
|
||
self.tabbarBGImage = image;
|
||
if (self.updateTabbarBG) {
|
||
self.updateTabbarBG(image);
|
||
}
|
||
} fail:^(NSError * _Nonnull error) {
|
||
@kStrongify(self);
|
||
if (self.updateTabbarBG) {
|
||
self.updateTabbarBG(kImage(@"tab_bar_bg"));
|
||
}
|
||
}];
|
||
}
|
||
|
||
- (void)loadBGColor {
|
||
[[NSNotificationCenter defaultCenter] postNotificationName:self.reloadNavigationAreaImageKey
|
||
object:nil];
|
||
}
|
||
|
||
- (UIColor *)bgColor {
|
||
if (self.uiSetting && ![NSString isEmpty:self.uiSetting.backgroundColor]) {
|
||
return [DJDKMIMOMColor colorWithHexString:self.uiSetting.backgroundColor];
|
||
}
|
||
|
||
return [DJDKMIMOMColor colorWithHexString:@"#FCF4DF"];
|
||
}
|
||
|
||
- (NSString *)tabName:(NSInteger)tabIndex {
|
||
return @[YMLocalizedString(@"TabbarViewController2"),
|
||
YMLocalizedString(@"TabbarViewController6"),
|
||
YMLocalizedString(@"TabbarViewController3"),
|
||
YMLocalizedString(@"TabbarViewController4"),
|
||
YMLocalizedString(@"TabbarViewController5")][tabIndex];
|
||
}
|
||
|
||
- (NSString *)loadDefaultNormalTabImageName:(NSInteger)tabIndex {
|
||
return @[@"tab_gameHome_normal",
|
||
@"tab_gameHome_game_normal",
|
||
@"tab_monents_normal",
|
||
@"tab_message_normal",
|
||
@"tab_mine_normal"][tabIndex];
|
||
}
|
||
|
||
- (NSString *)loadDefaultSelectedTabImageName:(NSInteger)tabIndex {
|
||
return @[@"tab_gameHome_selected",
|
||
@"tab_gameHome_game_selected",
|
||
@"tab_monents_select",
|
||
@"tab_message_selected",
|
||
@"tab_mine_selected"][tabIndex];
|
||
}
|
||
|
||
- (NSString *)loadConfigNormalTabImagePath:(NSInteger)tabIndex {
|
||
return [self.normalTabImageSource xpSafeObjectAtIndex:tabIndex];
|
||
}
|
||
|
||
- (NSString *)loadConfigSelectedTabImagePath:(NSInteger)tabIndex {
|
||
return [self.selectedTabImageSource xpSafeObjectAtIndex:tabIndex];
|
||
}
|
||
|
||
- (BOOL)shouldDisplayCaptcha {
|
||
return [self.configInfo captchaSwitch];
|
||
}
|
||
|
||
@end
|