BoxHeartbeatAlertTool.m 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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* buttonOKTitle = nil;
  58. NSString* buttonCloseTitle = NSLocalizedString(@"common_I_know",nil);
  59. BOOL isOkBtnHighlight = NO;
  60. if(type != 1){
  61. linkErrTitle = NSLocalizedString(@"Heartbeat_box_part_fail_title",nil);
  62. linkErrTip = NSLocalizedString(@"Heartbeat_box_part_fail_tip",nil);
  63. buttonOKTitle = NSLocalizedString(@"Heartbeat_box_restart_phone",nil);
  64. buttonCloseTitle = NSLocalizedString(@"common_close",nil);
  65. isOkBtnHighlight = YES;
  66. }
  67. KWeakSelf
  68. linkFailAlretVC= [[ComontAlretViewController alloc] initWithTiTle:linkErrTitle
  69. msg:linkErrTip
  70. imageStr:@""
  71. cancelTitle:buttonCloseTitle
  72. okTitle:buttonOKTitle
  73. isOkBtnHighlight:isOkBtnHighlight
  74. didClickOk:^{
  75. if(self->curDidClickButFun){
  76. self->curDidClickButFun(1);
  77. }
  78. if(type != 1){
  79. [weakSelf needToRebootFun];
  80. ksharedAppDelegate.needToShowReStratSucType = YES;
  81. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  82. BoxHeartbeatReStartView *view = [[BoxHeartbeatReStartView alloc] init];
  83. [ksharedAppDelegate.window addSubview:view];
  84. [view mas_makeConstraints:^(MASConstraintMaker *make) {
  85. make.left.mas_equalTo(0.f);
  86. make.bottom.mas_equalTo(0.f);
  87. make.right.mas_equalTo(0.f);
  88. make.top.mas_equalTo(0.f);
  89. }];
  90. });
  91. }
  92. } didClickCancel:^{
  93. }];
  94. linkFailAlretVC.modalPresentationStyle = UIModalPresentationCustom;
  95. [linkFailAlretVC setMsgTextAlignment:NSTextAlignmentLeft];
  96. [ksharedAppDelegate.window.rootViewController presentViewController:linkFailAlretVC animated:YES completion:^{
  97. self->linkFailAlretVC.view.superview.backgroundColor = [UIColor clearColor];
  98. }];
  99. linkFailAlretVC.view.tag = type;
  100. //添加一个删除按钮
  101. // UIView *whiteBgView = [linkFailAlretVC.view viewWithTag:999];
  102. // HLog(@"%@",whiteBgView);
  103. //
  104. // UIButton* delBut = [[UIButton alloc] init];
  105. // [delBut setImage:[UIImage imageNamed:@"common_del"] forState:UIControlStateNormal];
  106. // [delBut addTarget:self action:@selector(delViewFun) forControlEvents:UIControlEventTouchUpInside];
  107. // [whiteBgView addSubview:delBut];
  108. //
  109. // [delBut mas_makeConstraints:^(MASConstraintMaker *make) {
  110. // make.top.mas_equalTo(0);
  111. // make.right.mas_equalTo(0);
  112. // make.width.mas_equalTo(40);
  113. // make.height.mas_equalTo(40.0);
  114. // }];
  115. }
  116. //#pragma mark 用户点击关闭
  117. //- (void)delViewFun{
  118. // [linkFailAlretVC dismissViewControllerAnimated:YES completion:^{
  119. //
  120. // }];
  121. //}
  122. #pragma mark 重启云机
  123. - (void)needToRebootFun
  124. {
  125. linkFailAlretVC = nil;
  126. [[webRtcManager shareManager] needToRebootFun];
  127. [self startForceStartTimerFun];
  128. }
  129. #pragma mark 启动timer 秒后检查是否软件重启成功
  130. - (void)startForceStartTimerFun
  131. {
  132. KWeakSelf
  133. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  134. [weakSelf gotoUpdateForceStartFun];
  135. });
  136. }
  137. - (void)gotoUpdateForceStartFun
  138. {
  139. [self updateForceStartFun];
  140. //KWeakSelf
  141. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(30 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  142. //[weakSelf reconnectDevice];
  143. [[webRtcManager shareManager] relinkWebRtcFun];
  144. });
  145. }
  146. #pragma mark 需要强制重启
  147. - (void)updateForceStartFun{
  148. NSString* curSn = ksharedAppDelegate.DeviceThirdIdMod.data.changeSn;
  149. NSMutableDictionary *paraDict = [NSMutableDictionary dictionary];
  150. [paraDict setValue:curSn forKey:@"sn"];
  151. [paraDict setValue:[NSNumber numberWithBool:YES] forKey:@"isForceStart"];
  152. [[netWorkManager shareInstance] CommonPostCallBackCode:updateForceStart Parameters:paraDict success:^(id _Nonnull responseObject) {
  153. SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
  154. if (model.status == 0) {
  155. }
  156. else
  157. {
  158. }
  159. } failure:^(NSError * _Nonnull error) {
  160. HLog(@"%@", error);
  161. }];
  162. }
  163. @end