// // PISwitchingEnvironmentVC.m // YuMi // // Created by duoban on 2023/11/8. // #import "PISwitchingEnvironmentVC.h" #import "XPLoginViewController.h" #import "XPAdImageTool.h" #import "BaseNavigationController.h" @interface PISwitchingEnvironmentVC () @property(nonatomic,strong) UILabel *titleView; @end @implementation PISwitchingEnvironmentVC - (void)viewDidLoad { [super viewDidLoad]; self.title = @"切换"; NSString *isProduction = [[NSUserDefaults standardUserDefaults]valueForKey:@"kIsProductionEnvironment"]; NSString *text = @""; if([isProduction isEqualToString:@"YES"]){ text = @"当前环境:正式环境"; }else{ text = @"当前环境:测试环境"; } self.titleView = [UILabel labelInitWithText:text font:kFontMedium(16) textColor:[DJDKMIMOMColor mainTextColor]]; [self.view addSubview:self.titleView]; UILabel *switchTitle = [UILabel labelInitWithText:@"切换环境" font:kFontMedium(15) textColor:[DJDKMIMOMColor secondTextColor]]; [self.view addSubview:switchTitle]; UISwitch *switchView = [[UISwitch alloc]init]; [switchView setOn:[isProduction isEqualToString:@"YES"]]; [self.view addSubview:switchView]; [switchView addTarget:self action:@selector(switchEnvironmentAction:) forControlEvents:UIControlEventValueChanged]; UIButton *realBtn = [UIButton new]; [realBtn setTitle:@"调试捉包工具" forState:UIControlStateNormal]; realBtn.titleLabel.font = kFontMedium(16); [realBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; [realBtn addTarget:self action:@selector(showRealTimeView) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:realBtn]; [self.titleView mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.mas_equalTo(kGetScaleWidth(30)); make.top.mas_equalTo(kGetScaleWidth(100)); }]; [switchTitle mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.equalTo(self.titleView); make.top.equalTo(self.titleView.mas_bottom).mas_offset(kGetScaleWidth(20)); }]; [switchView mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.equalTo(switchTitle.mas_trailing).mas_offset(kGetScaleWidth(10)); make.centerY.equalTo(switchTitle); }]; [realBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.equalTo(self.titleView); make.top.equalTo(switchTitle.mas_bottom).mas_offset(kGetScaleWidth(30)); }]; } -(void)showRealTimeView{ [BSNetListenModel initRealTimeView]; UIWindow * window = [UIApplication sharedApplication].keyWindow; [BSNetListenModel sharedInstance:window]; } -(void)switchEnvironmentAction:(UISwitch *)sender{ TTAlertConfig *config = [[TTAlertConfig alloc]init]; config.title = @"提示"; config.message = @"确认切换网络环境吗?需要重启app"; [TTPopup alertWithConfig:config confirmHandler:^{ if(sender.isOn == YES){ [[NSUserDefaults standardUserDefaults]setValue:@"YES" forKey:@"kIsProductionEnvironment"]; [[NSUserDefaults standardUserDefaults]synchronize]; self.titleView.text = @"当前环境:正式环境"; [self logoutAction]; return; } [[NSUserDefaults standardUserDefaults]setValue:@"NO" forKey:@"kIsProductionEnvironment"]; [[NSUserDefaults standardUserDefaults]synchronize]; self.titleView.text = @"当前环境:测试环境"; [self logoutAction]; } cancelHandler:^{ [sender setOn:!sender.isOn]; }]; } -(void)logoutAction{ exit(0); } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end