// // 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 #import "NSString+Utils.h" #import "YYUtility.h" #import "XPWeakTimer.h" #import "Api+Main.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]; 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; [[NSNotificationCenter defaultCenter] postNotificationName:@"reloadAfterLoadConfig" object:nil]; } 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)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"]]; } if (finish) { finish(); } }]; } @end