// // 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* buttonTitle = NSLocalizedString(@"common_I_know",nil); if(type != 1){ linkErrTitle = NSLocalizedString(@"Heartbeat_box_part_fail_title",nil); linkErrTip = NSLocalizedString(@"Heartbeat_box_part_fail_tip",nil); buttonTitle = NSLocalizedString(@"Heartbeat_box_restart_phone",nil); } KWeakSelf linkFailAlretVC= [[ComontAlretViewController alloc] initWithTiTle:linkErrTitle msg:linkErrTip imageStr:@"" cancelTitle:buttonTitle okTitle:@"" isOkBtnHighlight:NO didClickOk:^{ } didClickCancel:^{ 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); }]; }); } }]; 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; } #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