BoxHeartbeatAlertTool.m 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. //
  2. // BoxHeartbeatAlertTool.m
  3. // 隐私保护
  4. //
  5. // Created by xd h on 2025/2/7.
  6. //
  7. #import "BoxHeartbeatAlertTool.h"
  8. #import "ComontAlretViewController.h"
  9. //#import "ComontAlretType2ViewController.h"
  10. #import "BoxHeartbeatReStartView.h"
  11. static BoxHeartbeatAlertTool *shareInstance = nil;
  12. @interface BoxHeartbeatAlertTool ()
  13. {
  14. /*弹窗提示链接失败 网络或者云机*/
  15. ComontAlretViewController *linkFailAlretVC;
  16. //ComontAlretType2ViewController * linkFailAlretType2VC;
  17. BoxHeartbeat_DidClickButFun curDidClickButFun;
  18. }
  19. @end
  20. @implementation BoxHeartbeatAlertTool
  21. + (instancetype)shareInstance {
  22. static dispatch_once_t onceToken;
  23. dispatch_once(&onceToken, ^{
  24. shareInstance = [[BoxHeartbeatAlertTool alloc] init];
  25. });
  26. return shareInstance;
  27. }
  28. #pragma mark 网络异常弹框 消失
  29. - (void)dismissErrorAlertFun
  30. {
  31. KWeakSelf
  32. mainBlock(^{
  33. [weakSelf dismissErrorAlertInMainFun];
  34. });
  35. }
  36. - (void)dismissErrorAlertInMainFun{
  37. if(linkFailAlretVC){
  38. [self->linkFailAlretVC dismissViewControllerAnimated:YES completion:^{
  39. }];
  40. self->linkFailAlretVC = nil;
  41. }
  42. }
  43. #pragma mark 网络异常弹框
  44. -(void)showBoxHeartbeatAlertFun:(NSInteger)type didClickBut:(BoxHeartbeat_DidClickButFun)didClickBut
  45. {
  46. curDidClickButFun = didClickBut;
  47. ksharedAppDelegate.didShowBoxHeartbeatAlertType = YES;
  48. KWeakSelf
  49. mainBlock(^{
  50. [weakSelf showNetErrorAlertFunInMain:type];
  51. });
  52. }
  53. -(void)showNetErrorAlertFunInMain:(NSInteger)type
  54. {
  55. NSString* linkErrTitle = NSLocalizedString(@"Heartbeat_box_all_fail_title",nil);
  56. NSString* linkErrTip = NSLocalizedString(@"Heartbeat_box_all_fail_tip",nil);
  57. NSString* buttonTitle = NSLocalizedString(@"common_I_know",nil);
  58. if(type != 1){
  59. linkErrTitle = NSLocalizedString(@"Heartbeat_box_part_fail_title",nil);
  60. linkErrTip = NSLocalizedString(@"Heartbeat_box_part_fail_tip",nil);
  61. buttonTitle = NSLocalizedString(@"Heartbeat_box_restart_phone",nil);
  62. }
  63. KWeakSelf
  64. linkFailAlretVC= [[ComontAlretViewController alloc] initWithTiTle:linkErrTitle
  65. msg:linkErrTip
  66. imageStr:@""
  67. cancelTitle:buttonTitle
  68. okTitle:@""
  69. isOkBtnHighlight:NO
  70. didClickOk:^{
  71. } didClickCancel:^{
  72. if(self->curDidClickButFun){
  73. self->curDidClickButFun(1);
  74. }
  75. if(type != 1){
  76. [weakSelf needToRebootFun];
  77. ksharedAppDelegate.needToShowReStratSucType = YES;
  78. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  79. BoxHeartbeatReStartView *view = [[BoxHeartbeatReStartView alloc] init];
  80. [ksharedAppDelegate.window addSubview:view];
  81. [view mas_makeConstraints:^(MASConstraintMaker *make) {
  82. make.left.mas_equalTo(0.f);
  83. make.bottom.mas_equalTo(0.f);
  84. make.right.mas_equalTo(0.f);
  85. make.top.mas_equalTo(0.f);
  86. }];
  87. });
  88. }
  89. }];
  90. linkFailAlretVC.modalPresentationStyle = UIModalPresentationCustom;
  91. [linkFailAlretVC setMsgTextAlignment:NSTextAlignmentLeft];
  92. [ksharedAppDelegate.window.rootViewController presentViewController:linkFailAlretVC animated:YES completion:^{
  93. self->linkFailAlretVC.view.superview.backgroundColor = [UIColor clearColor];
  94. }];
  95. linkFailAlretVC.view.tag = type;
  96. }
  97. #pragma mark 重启云机
  98. - (void)needToRebootFun
  99. {
  100. linkFailAlretVC = nil;
  101. [[webRtcManager shareManager] needToRebootFun];
  102. [self startForceStartTimerFun];
  103. }
  104. #pragma mark 启动timer 秒后检查是否软件重启成功
  105. - (void)startForceStartTimerFun
  106. {
  107. KWeakSelf
  108. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  109. [weakSelf gotoUpdateForceStartFun];
  110. });
  111. }
  112. - (void)gotoUpdateForceStartFun
  113. {
  114. [self updateForceStartFun];
  115. //KWeakSelf
  116. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(30 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  117. //[weakSelf reconnectDevice];
  118. [[webRtcManager shareManager] relinkWebRtcFun];
  119. });
  120. }
  121. #pragma mark 需要强制重启
  122. - (void)updateForceStartFun{
  123. NSString* curSn = ksharedAppDelegate.DeviceThirdIdMod.data.changeSn;
  124. NSMutableDictionary *paraDict = [NSMutableDictionary dictionary];
  125. [paraDict setValue:curSn forKey:@"sn"];
  126. [paraDict setValue:[NSNumber numberWithBool:YES] forKey:@"isForceStart"];
  127. [[netWorkManager shareInstance] CommonPostCallBackCode:updateForceStart Parameters:paraDict success:^(id _Nonnull responseObject) {
  128. SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
  129. if (model.status == 0) {
  130. }
  131. else
  132. {
  133. }
  134. } failure:^(NSError * _Nonnull error) {
  135. HLog(@"%@", error);
  136. }];
  137. }
  138. @end