errorAlertTool~.m 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. //
  2. // errorAlertTool.m
  3. // 双子星云手机
  4. //
  5. // Created by xd h on 2024/7/20.
  6. //
  7. #import "errorAlertTool.h"
  8. #import "ComontAlretViewController.h"
  9. #import "ComontAlretType2ViewController.h"
  10. static errorAlertTool *shareInstance = nil;
  11. @interface errorAlertTool ()
  12. {
  13. /*弹窗提示链接失败 网络或者云机*/
  14. ComontAlretViewController *linkFailAlretVC;
  15. ComontAlretType2ViewController * linkFailAlretType2VC;
  16. NSTimer *forceStartTimer;//通知服务器重启timer
  17. errorAlert_DidClickButFun curDidClickButFun;
  18. }
  19. @end
  20. @implementation errorAlertTool
  21. + (instancetype)shareInstance {
  22. static dispatch_once_t onceToken;
  23. dispatch_once(&onceToken, ^{
  24. shareInstance = [[errorAlertTool 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)showNetErrorAlertFun:(NSInteger)type didClickBut:(errorAlert_DidClickButFun)didClickBut
  45. {
  46. curDidClickButFun = didClickBut;
  47. KWeakSelf
  48. mainBlock(^{
  49. [weakSelf showNetErrorAlertFunInMain:type];
  50. });
  51. }
  52. -(void)showNetErrorAlertFunInMain:(NSInteger)type
  53. {
  54. [cachesFileManager writeLogsWithMsg:[[NSString alloc] initWithFormat:@"showNetErrorAlertFun %ld",type]];
  55. if(linkFailAlretVC
  56. //||[connectDeviceManager shareInstance].isReInitType//瑞云重新init 耗时2-7s 他们说的
  57. ||(ksharedAppDelegate.isWebSockLinkOKAginType && type == 2) //重连上了但是延时消息来了
  58. ||linkFailAlretType2VC){
  59. return;
  60. }
  61. //重启后重连 出来的
  62. if([webRtcManager shareManager].isRebootIngType){
  63. // if(![self isPlayerViewIsTopVCFun]){
  64. // [[iToast makeText:NSLocalizedString(@"player_link_rebooting_Tips",nil)] show];
  65. // }
  66. return;
  67. }
  68. if([webRtcManager shareManager].isResetingType){
  69. // if(![self isPlayerViewIsTopVCFun]){
  70. // [[iToast makeText:NSLocalizedString(@"my_set_no_Restore_Factorying_tips",nil)] show];
  71. // }
  72. return;
  73. }
  74. //切换盒子 出来的
  75. if([webRtcManager shareManager].isChangeBoxType){
  76. return;
  77. }
  78. //被挤下线
  79. if([webRtcManager shareManager].isLogoutByOtherType){
  80. return;
  81. }
  82. if(ksharedAppDelegate.isDidShowPwdType){
  83. //等下再发
  84. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  85. [self showNetErrorAlertFunInMain:type];
  86. });
  87. return;
  88. }
  89. //未连接成功过
  90. // if(_isFirstEnterPhone && type == 5){
  91. // type = 1;
  92. // }
  93. BOOL isPhoneNetWorkWrongType = NO;
  94. NSString *linkErrTip = NSLocalizedString(@"player_link_fail_tip_type11",nil);
  95. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable){
  96. linkErrTip = NSLocalizedString(@"netWork_error_tip_content",nil);
  97. isPhoneNetWorkWrongType = YES;
  98. }
  99. if(type == 11 && !isPhoneNetWorkWrongType){
  100. NSString* linkErrTitle = NSLocalizedString(@"player_link_fail_title_type11",nil);
  101. linkErrTitle = [[NSString alloc] initWithFormat:@"[%ld]%@",type,linkErrTitle];
  102. KWeakSelf
  103. linkFailAlretType2VC = [[ComontAlretType2ViewController alloc] initWithTitle:linkErrTitle msg:linkErrTip imageStr:@"" cancelTitle:NSLocalizedString(@"single_sign_on_exit",nil) okTitle:NSLocalizedString(@"player_link_fail_tryAgain",nil) otherTitle:NSLocalizedString(@"my_set_no_restart_phone",nil) isOkBtnHighlight:YES didClickOk:^{
  104. [weakSelf tryAgainInLinkFailFun];
  105. [cachesFileManager writeLogsWithMsg:@"click tryAgain"];
  106. if(self->curDidClickButFun){
  107. self->curDidClickButFun(1);
  108. }
  109. } didClickCancel:^{
  110. if(type == 5){
  111. self->curDidClickButFun(5);
  112. }
  113. else{
  114. exit(0);
  115. }
  116. } didClickOther:^{//重启云机
  117. [weakSelf needToRebootFun];
  118. if(self->curDidClickButFun){
  119. self->curDidClickButFun(3);
  120. }
  121. }];
  122. linkFailAlretType2VC.modalPresentationStyle = UIModalPresentationCustom;
  123. [ksharedAppDelegate.window.rootViewController presentViewController:linkFailAlretType2VC animated:YES completion:^{
  124. self->linkFailAlretType2VC.view.superview.backgroundColor = [UIColor clearColor];
  125. }];
  126. }
  127. else{
  128. NSString* linkErrTitle = @"";
  129. if(type == 2
  130. ||type==5
  131. ||type==1
  132. ||type==12){
  133. linkErrTitle = NSLocalizedString(@"player_link_fail_title_type2",nil);
  134. linkErrTip = NSLocalizedString(@"player_link_fail_tip_type2",nil);
  135. }
  136. else{
  137. linkErrTitle = NSLocalizedString(@"player_link_fail_title_type3",nil);
  138. linkErrTip = NSLocalizedString(@"player_link_fail_tip_type2",nil);
  139. }
  140. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable){
  141. linkErrTip = NSLocalizedString(@"netWork_error_tip_content",nil);
  142. }
  143. linkErrTitle = [[NSString alloc] initWithFormat:@"[%ld]%@",type,linkErrTitle];
  144. KWeakSelf
  145. linkFailAlretVC= [[ComontAlretViewController alloc] initWithTiTle:linkErrTitle
  146. msg:linkErrTip
  147. imageStr:@""
  148. cancelTitle:NSLocalizedString(@"single_sign_on_exit",nil)
  149. okTitle:NSLocalizedString(@"player_link_fail_tryAgain",nil) isOkBtnHighlight:YES
  150. didClickOk:^{
  151. [weakSelf tryAgainInLinkFailFun];
  152. [cachesFileManager writeLogsWithMsg:@"click tryAgain"];
  153. if(self->curDidClickButFun){
  154. self->curDidClickButFun(1);
  155. }
  156. } didClickCancel:^{
  157. exit(0);
  158. }];
  159. linkFailAlretVC.modalPresentationStyle = UIModalPresentationCustom;
  160. [linkFailAlretVC setMsgTextAlignment:NSTextAlignmentLeft];
  161. [ksharedAppDelegate.window.rootViewController presentViewController:linkFailAlretVC animated:YES completion:^{
  162. self->linkFailAlretVC.view.superview.backgroundColor = [UIColor clearColor];
  163. }];
  164. }
  165. linkFailAlretVC.view.tag = type;
  166. }
  167. - (void)tryAgainInLinkFailFun
  168. {
  169. linkFailAlretVC = nil;
  170. linkFailAlretType2VC = nil;
  171. // if([[connectDeviceManager shareInstance] curConnectDeviceState] <= 3)
  172. // {
  173. // //瑞云发起重连
  174. // NSString *snStr = ksharedAppDelegate.DeviceThirdIdMod.data.changeSn;
  175. // if(snStr){
  176. // //_checkThridConnectNum = 1;
  177. // [[connectDeviceManager shareInstance] getThridMsgBySN:snStr needReconnect:YES didNetEnd:^(NSInteger didSuc) {
  178. // }];
  179. // }
  180. // return;
  181. // }
  182. if(!ksharedAppDelegate.isWebSockLinkOKAginType){
  183. [[webRtcManager shareManager] beginToLinkWebRtcFun];
  184. return;
  185. }
  186. //[[connectDeviceManager shareInstance] tryReconnectFun];
  187. // [self showNewIndicator];
  188. // reConnectAccount = 0;
  189. // [self tryAgain];
  190. }
  191. #pragma mark 重启云机
  192. - (void)needToRebootFun
  193. {
  194. [[webRtcManager shareManager] needToRebootFun];
  195. [self startForceStartTimerFun];
  196. }
  197. #pragma mark 启动timer 秒后检查是否软件重启成功
  198. - (void)startForceStartTimerFun
  199. {
  200. if(forceStartTimer){
  201. [forceStartTimer invalidate];
  202. forceStartTimer = nil;
  203. }
  204. forceStartTimer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(gotoUpdateForceStartFun) userInfo:nil repeats:NO];
  205. [[NSRunLoop currentRunLoop] addTimer:forceStartTimer forMode:NSRunLoopCommonModes];
  206. }
  207. - (void)gotoUpdateForceStartFun
  208. {
  209. [self updateForceStartFun];
  210. KWeakSelf
  211. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(30 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  212. //[weakSelf reconnectDevice];
  213. [[webRtcManager shareManager] relinkWebRtcFun];
  214. });
  215. }
  216. #pragma mark 需要强制重启
  217. - (void)updateForceStartFun{
  218. NSString* curSn = ksharedAppDelegate.DeviceThirdIdMod.data.changeSn;
  219. NSMutableDictionary *paraDict = [NSMutableDictionary dictionary];
  220. [paraDict setValue:curSn forKey:@"sn"];
  221. [paraDict setValue:[NSNumber numberWithBool:YES] forKey:@"isForceStart"];
  222. [[netWorkManager shareInstance] CommonPostCallBackCode:updateForceStart Parameters:paraDict success:^(id _Nonnull responseObject) {
  223. SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
  224. if (model.status == 0) {
  225. }
  226. else
  227. {
  228. }
  229. } failure:^(NSError * _Nonnull error) {
  230. HLog(@"%@", error);
  231. }];
  232. }
  233. @end