errorAlertTool.m 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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([webSocketManager shareInstance].isRebootIngType){
  63. // if(![self isPlayerViewIsTopVCFun]){
  64. // [[iToast makeText:NSLocalizedString(@"player_link_rebooting_Tips",nil)] show];
  65. // }
  66. return;
  67. }
  68. if([webSocketManager shareInstance].isResetingType){
  69. // if(![self isPlayerViewIsTopVCFun]){
  70. // [[iToast makeText:NSLocalizedString(@"my_set_no_Restore_Factorying_tips",nil)] show];
  71. // }
  72. return;
  73. }
  74. //切换盒子 出来的
  75. if([webSocketManager shareInstance].isChangeBoxType){
  76. return;
  77. }
  78. //被挤下线
  79. if([webSocketManager shareInstance].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. exit(0);
  111. } didClickOther:^{//重启云机
  112. [weakSelf needToRebootFun];
  113. if(self->curDidClickButFun){
  114. self->curDidClickButFun(3);
  115. }
  116. }];
  117. linkFailAlretType2VC.modalPresentationStyle = UIModalPresentationCustom;
  118. [ksharedAppDelegate.window.rootViewController presentViewController:linkFailAlretType2VC animated:YES completion:^{
  119. self->linkFailAlretType2VC.view.superview.backgroundColor = [UIColor clearColor];
  120. }];
  121. }
  122. else{
  123. NSString* linkErrTitle = @"";
  124. if(type == 2
  125. ||type==5
  126. ||type==1
  127. ||type==12){
  128. linkErrTitle = NSLocalizedString(@"player_link_fail_title_type2",nil);
  129. linkErrTip = NSLocalizedString(@"player_link_fail_tip_type2",nil);
  130. }
  131. else{
  132. linkErrTitle = NSLocalizedString(@"player_link_fail_title_type3",nil);
  133. linkErrTip = NSLocalizedString(@"player_link_fail_tip_type2",nil);
  134. }
  135. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable){
  136. linkErrTip = NSLocalizedString(@"netWork_error_tip_content",nil);
  137. }
  138. linkErrTitle = [[NSString alloc] initWithFormat:@"[%ld]%@",type,linkErrTitle];
  139. KWeakSelf
  140. linkFailAlretVC= [[ComontAlretViewController alloc] initWithTiTle:linkErrTitle
  141. msg:linkErrTip
  142. imageStr:@""
  143. cancelTitle:NSLocalizedString(@"single_sign_on_exit",nil)
  144. okTitle:NSLocalizedString(@"player_link_fail_tryAgain",nil) isOkBtnHighlight:YES
  145. didClickOk:^{
  146. [weakSelf tryAgainInLinkFailFun];
  147. [cachesFileManager writeLogsWithMsg:@"click tryAgain"];
  148. if(self->curDidClickButFun){
  149. self->curDidClickButFun(1);
  150. }
  151. } didClickCancel:^{
  152. exit(0);
  153. }];
  154. linkFailAlretVC.modalPresentationStyle = UIModalPresentationCustom;
  155. [linkFailAlretVC setMsgTextAlignment:NSTextAlignmentLeft];
  156. [ksharedAppDelegate.window.rootViewController presentViewController:linkFailAlretVC animated:YES completion:^{
  157. self->linkFailAlretVC.view.superview.backgroundColor = [UIColor clearColor];
  158. }];
  159. }
  160. linkFailAlretVC.view.tag = type;
  161. }
  162. - (void)tryAgainInLinkFailFun
  163. {
  164. linkFailAlretVC = nil;
  165. linkFailAlretType2VC = nil;
  166. if([[connectDeviceManager shareInstance] curConnectDeviceState] <= 3)
  167. {
  168. //瑞云发起重连
  169. NSString *snStr = ksharedAppDelegate.DeviceThirdIdMod.data.changeSn;
  170. if(snStr){
  171. //_checkThridConnectNum = 1;
  172. [[connectDeviceManager shareInstance] getThridMsgBySN:snStr needReconnect:YES didNetEnd:^(NSInteger didSuc) {
  173. }];
  174. }
  175. return;
  176. }
  177. //[[connectDeviceManager shareInstance] tryReconnectFun];
  178. // [self showNewIndicator];
  179. // reConnectAccount = 0;
  180. // [self tryAgain];
  181. }
  182. #pragma mark 重启云机
  183. - (void)needToRebootFun
  184. {
  185. [[webSocketManager shareInstance] needToRebootFun];
  186. [self startForceStartTimerFun];
  187. }
  188. #pragma mark 启动timer 秒后检查是否软件重启成功
  189. - (void)startForceStartTimerFun
  190. {
  191. if(forceStartTimer){
  192. [forceStartTimer invalidate];
  193. forceStartTimer = nil;
  194. }
  195. forceStartTimer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(gotoUpdateForceStartFun) userInfo:nil repeats:NO];
  196. [[NSRunLoop currentRunLoop] addTimer:forceStartTimer forMode:NSRunLoopCommonModes];
  197. }
  198. - (void)gotoUpdateForceStartFun
  199. {
  200. [self updateForceStartFun];
  201. KWeakSelf
  202. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(30 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  203. //[weakSelf reconnectDevice];
  204. [[webSocketManager shareInstance] WebSocketNeedRelinkFun];
  205. });
  206. }
  207. #pragma mark 需要强制重启
  208. - (void)updateForceStartFun{
  209. NSString* curSn = ksharedAppDelegate.DeviceThirdIdMod.data.changeSn;
  210. NSMutableDictionary *paraDict = [NSMutableDictionary dictionary];
  211. [paraDict setValue:curSn forKey:@"sn"];
  212. [paraDict setValue:[NSNumber numberWithBool:YES] forKey:@"isForceStart"];
  213. [[netWorkManager shareInstance] CommonPostCallBackCode:updateForceStart Parameters:paraDict success:^(id _Nonnull responseObject) {
  214. SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
  215. if (model.status == 0) {
  216. }
  217. else
  218. {
  219. }
  220. } failure:^(NSError * _Nonnull error) {
  221. HLog(@"%@", error);
  222. }];
  223. }
  224. @end