// // BoxHeartbeatAlertTool.m // 隐私保护 // // Created by xd h on 2025/2/7. // #import "BoxHeartbeatAlertTool.h" #import "ComontAlretViewController.h" //#import "ComontAlretType2ViewController.h" #import "BoxHeartbeatReStartView.h" static BoxHeartbeatAlertTool *shareInstance = nil; @interface BoxHeartbeatAlertTool () { /*弹窗提示链接失败 网络或者云机*/ ComontAlretViewController *linkFailAlretVC; //ComontAlretType2ViewController * linkFailAlretType2VC; BoxHeartbeat_DidClickButFun curDidClickButFun; } @end @implementation BoxHeartbeatAlertTool + (instancetype)shareInstance { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ shareInstance = [[BoxHeartbeatAlertTool alloc] init]; }); return shareInstance; } #pragma mark 网络异常弹框 消失 - (void)dismissErrorAlertFun { KWeakSelf mainBlock(^{ [weakSelf dismissErrorAlertInMainFun]; }); } - (void)dismissErrorAlertInMainFun{ if(linkFailAlretVC){ [self->linkFailAlretVC dismissViewControllerAnimated:YES completion:^{ }]; self->linkFailAlretVC = nil; } } #pragma mark 网络异常弹框 -(void)showBoxHeartbeatAlertFun:(NSInteger)type didClickBut:(BoxHeartbeat_DidClickButFun)didClickBut { curDidClickButFun = didClickBut; ksharedAppDelegate.didShowBoxHeartbeatAlertType = YES; KWeakSelf mainBlock(^{ [weakSelf showNetErrorAlertFunInMain:type]; }); } -(void)showNetErrorAlertFunInMain:(NSInteger)type { NSString* linkErrTitle = NSLocalizedString(@"Heartbeat_box_all_fail_title",nil); NSString* linkErrTip = NSLocalizedString(@"Heartbeat_box_all_fail_tip",nil); NSString* buttonOKTitle = nil; NSString* buttonCloseTitle = NSLocalizedString(@"common_I_know",nil); BOOL isOkBtnHighlight = NO; if(type != 1){ linkErrTitle = NSLocalizedString(@"Heartbeat_box_part_fail_title",nil); linkErrTip = NSLocalizedString(@"Heartbeat_box_part_fail_tip",nil); buttonOKTitle = NSLocalizedString(@"Heartbeat_box_restart_phone",nil); buttonCloseTitle = NSLocalizedString(@"common_close",nil); isOkBtnHighlight = YES; } KWeakSelf linkFailAlretVC= [[ComontAlretViewController alloc] initWithTiTle:linkErrTitle msg:linkErrTip imageStr:@"" cancelTitle:buttonCloseTitle okTitle:buttonOKTitle isOkBtnHighlight:isOkBtnHighlight didClickOk:^{ if(self->curDidClickButFun){ self->curDidClickButFun(1); } if(type != 1){ [weakSelf needToRebootFun]; ksharedAppDelegate.needToShowReStratSucType = YES; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ BoxHeartbeatReStartView *view = [[BoxHeartbeatReStartView alloc] init]; [ksharedAppDelegate.window addSubview:view]; [view mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0.f); make.bottom.mas_equalTo(0.f); make.right.mas_equalTo(0.f); make.top.mas_equalTo(0.f); }]; }); } } didClickCancel:^{ }]; linkFailAlretVC.modalPresentationStyle = UIModalPresentationCustom; [linkFailAlretVC setMsgTextAlignment:NSTextAlignmentLeft]; [ksharedAppDelegate.window.rootViewController presentViewController:linkFailAlretVC animated:YES completion:^{ self->linkFailAlretVC.view.superview.backgroundColor = [UIColor clearColor]; }]; linkFailAlretVC.view.tag = type; //添加一个删除按钮 // UIView *whiteBgView = [linkFailAlretVC.view viewWithTag:999]; // HLog(@"%@",whiteBgView); // // UIButton* delBut = [[UIButton alloc] init]; // [delBut setImage:[UIImage imageNamed:@"common_del"] forState:UIControlStateNormal]; // [delBut addTarget:self action:@selector(delViewFun) forControlEvents:UIControlEventTouchUpInside]; // [whiteBgView addSubview:delBut]; // // [delBut mas_makeConstraints:^(MASConstraintMaker *make) { // make.top.mas_equalTo(0); // make.right.mas_equalTo(0); // make.width.mas_equalTo(40); // make.height.mas_equalTo(40.0); // }]; } //#pragma mark 用户点击关闭 //- (void)delViewFun{ // [linkFailAlretVC dismissViewControllerAnimated:YES completion:^{ // // }]; //} #pragma mark 重启云机 - (void)needToRebootFun { linkFailAlretVC = nil; [[webRtcManager shareManager] needToRebootFun]; [self startForceStartTimerFun]; } #pragma mark 启动timer 秒后检查是否软件重启成功 - (void)startForceStartTimerFun { KWeakSelf dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [weakSelf gotoUpdateForceStartFun]; }); } - (void)gotoUpdateForceStartFun { [self updateForceStartFun]; //KWeakSelf dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(30 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ //[weakSelf reconnectDevice]; [[webRtcManager shareManager] relinkWebRtcFun]; }); } #pragma mark 需要强制重启 - (void)updateForceStartFun{ NSString* curSn = ksharedAppDelegate.DeviceThirdIdMod.data.changeSn; NSMutableDictionary *paraDict = [NSMutableDictionary dictionary]; [paraDict setValue:curSn forKey:@"sn"]; [paraDict setValue:[NSNumber numberWithBool:YES] forKey:@"isForceStart"]; [[netWorkManager shareInstance] CommonPostCallBackCode:updateForceStart Parameters:paraDict success:^(id _Nonnull responseObject) { SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil]; if (model.status == 0) { } else { } } failure:^(NSError * _Nonnull error) { HLog(@"%@", error); }]; } @end