|
|
@@ -0,0 +1,281 @@
|
|
|
+//
|
|
|
+// errorAlertTool.m
|
|
|
+// 双子星云手机
|
|
|
+//
|
|
|
+// Created by xd h on 2024/7/20.
|
|
|
+//
|
|
|
+
|
|
|
+#import "errorAlertTool.h"
|
|
|
+#import "ComontAlretViewController.h"
|
|
|
+#import "ComontAlretType2ViewController.h"
|
|
|
+
|
|
|
+static errorAlertTool *shareInstance = nil;
|
|
|
+
|
|
|
+@interface errorAlertTool ()
|
|
|
+{
|
|
|
+ /*弹窗提示链接失败 网络或者云机*/
|
|
|
+ ComontAlretViewController *linkFailAlretVC;
|
|
|
+ ComontAlretType2ViewController * linkFailAlretType2VC;
|
|
|
+
|
|
|
+ NSTimer *forceStartTimer;//通知服务器重启timer
|
|
|
+
|
|
|
+ errorAlert_DidClickButFun curDidClickButFun;
|
|
|
+}
|
|
|
+
|
|
|
+@end
|
|
|
+
|
|
|
+@implementation errorAlertTool
|
|
|
+
|
|
|
++ (instancetype)shareInstance {
|
|
|
+
|
|
|
+ static dispatch_once_t onceToken;
|
|
|
+
|
|
|
+ dispatch_once(&onceToken, ^{
|
|
|
+ shareInstance = [[errorAlertTool 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)showNetErrorAlertFun:(NSInteger)type didClickBut:(errorAlert_DidClickButFun)didClickBut
|
|
|
+{
|
|
|
+ curDidClickButFun = didClickBut;
|
|
|
+ KWeakSelf
|
|
|
+ mainBlock(^{
|
|
|
+ [weakSelf showNetErrorAlertFunInMain:type];
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+-(void)showNetErrorAlertFunInMain:(NSInteger)type
|
|
|
+{
|
|
|
+
|
|
|
+ [cachesFileManager writeLogsWithMsg:[[NSString alloc] initWithFormat:@"showNetErrorAlertFun %ld",type]];
|
|
|
+
|
|
|
+ if(linkFailAlretVC
|
|
|
+ ||[connectDeviceManager shareInstance].isReInitType//瑞云重新init 耗时2-7s 他们说的
|
|
|
+ ||(ksharedAppDelegate.isWebSockLinkOKAginType && type == 2) //重连上了但是延时消息来了
|
|
|
+ ||linkFailAlretType2VC){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //重启后重连 出来的
|
|
|
+ if([webSocketManager shareInstance].isRebootIngType){
|
|
|
+// if(![self isPlayerViewIsTopVCFun]){
|
|
|
+// [[iToast makeText:NSLocalizedString(@"player_link_rebooting_Tips",nil)] show];
|
|
|
+// }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if([webSocketManager shareInstance].isResetingType){
|
|
|
+// if(![self isPlayerViewIsTopVCFun]){
|
|
|
+// [[iToast makeText:NSLocalizedString(@"my_set_no_Restore_Factorying_tips",nil)] show];
|
|
|
+// }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //切换盒子 出来的
|
|
|
+ if([webSocketManager shareInstance].isChangeBoxType){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+// if([self isPlayerViewIsTopVCFun]){
|
|
|
+//
|
|
|
+// //等下再发
|
|
|
+// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
|
+// [self showNetErrorAlertFun:type];
|
|
|
+// });
|
|
|
+// return;
|
|
|
+// }
|
|
|
+
|
|
|
+ //未连接成功过
|
|
|
+// if(_isFirstEnterPhone && type == 5){
|
|
|
+// type = 1;
|
|
|
+// }
|
|
|
+
|
|
|
+ BOOL isPhoneNetWorkWrongType = NO;
|
|
|
+ NSString *linkErrTip = NSLocalizedString(@"player_link_fail_tip_type11",nil);
|
|
|
+ if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable){
|
|
|
+ linkErrTip = NSLocalizedString(@"netWork_error_tip_content",nil);
|
|
|
+ isPhoneNetWorkWrongType = YES;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(type == 11 && !isPhoneNetWorkWrongType){
|
|
|
+ NSString* linkErrTitle = NSLocalizedString(@"player_link_fail_title_type11",nil);
|
|
|
+ linkErrTitle = [[NSString alloc] initWithFormat:@"[%ld]%@",type,linkErrTitle];
|
|
|
+
|
|
|
+ KWeakSelf
|
|
|
+ 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:^{
|
|
|
+ [weakSelf tryAgainInLinkFailFun];
|
|
|
+ [cachesFileManager writeLogsWithMsg:@"click tryAgain"];
|
|
|
+
|
|
|
+ if(self->curDidClickButFun){
|
|
|
+ self->curDidClickButFun(1);
|
|
|
+ }
|
|
|
+ } didClickCancel:^{
|
|
|
+ exit(0);
|
|
|
+ } didClickOther:^{//重启云机
|
|
|
+ [weakSelf needToRebootFun];
|
|
|
+
|
|
|
+ if(self->curDidClickButFun){
|
|
|
+ self->curDidClickButFun(3);
|
|
|
+ }
|
|
|
+ }];
|
|
|
+
|
|
|
+
|
|
|
+ linkFailAlretType2VC.modalPresentationStyle = UIModalPresentationCustom;
|
|
|
+
|
|
|
+ [ksharedAppDelegate.window.rootViewController presentViewController:linkFailAlretType2VC animated:YES completion:^{
|
|
|
+ self->linkFailAlretType2VC.view.superview.backgroundColor = [UIColor clearColor];
|
|
|
+ }];
|
|
|
+
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ NSString* linkErrTitle = @"";
|
|
|
+ if(type == 2
|
|
|
+ ||type==5
|
|
|
+ ||type==1
|
|
|
+ ||type==12){
|
|
|
+ linkErrTitle = NSLocalizedString(@"player_link_fail_title_type2",nil);
|
|
|
+ linkErrTip = NSLocalizedString(@"player_link_fail_tip_type2",nil);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ linkErrTitle = NSLocalizedString(@"player_link_fail_title_type3",nil);
|
|
|
+ linkErrTip = NSLocalizedString(@"player_link_fail_tip_type2",nil);
|
|
|
+ }
|
|
|
+
|
|
|
+ if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable){
|
|
|
+ linkErrTip = NSLocalizedString(@"netWork_error_tip_content",nil);
|
|
|
+ }
|
|
|
+
|
|
|
+ linkErrTitle = [[NSString alloc] initWithFormat:@"[%ld]%@",type,linkErrTitle];
|
|
|
+
|
|
|
+ KWeakSelf
|
|
|
+ linkFailAlretVC= [[ComontAlretViewController alloc] initWithTiTle:linkErrTitle
|
|
|
+ msg:linkErrTip
|
|
|
+ imageStr:@""
|
|
|
+ cancelTitle:NSLocalizedString(@"single_sign_on_exit",nil)
|
|
|
+ okTitle:NSLocalizedString(@"player_link_fail_tryAgain",nil) isOkBtnHighlight:YES
|
|
|
+ didClickOk:^{
|
|
|
+ [weakSelf tryAgainInLinkFailFun];
|
|
|
+ [cachesFileManager writeLogsWithMsg:@"click tryAgain"];
|
|
|
+
|
|
|
+ if(self->curDidClickButFun){
|
|
|
+ self->curDidClickButFun(1);
|
|
|
+ }
|
|
|
+ } didClickCancel:^{
|
|
|
+ exit(0);
|
|
|
+ }];
|
|
|
+
|
|
|
+ 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;
|
|
|
+}
|
|
|
+
|
|
|
+- (void)tryAgainInLinkFailFun
|
|
|
+{
|
|
|
+ linkFailAlretVC = nil;
|
|
|
+ linkFailAlretType2VC = nil;
|
|
|
+
|
|
|
+ if([[connectDeviceManager shareInstance] curConnectDeviceState] <= 3)
|
|
|
+ {
|
|
|
+ //瑞云发起重连
|
|
|
+ NSString *snStr = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.changeSn;
|
|
|
+ if(snStr){
|
|
|
+ //_checkThridConnectNum = 1;
|
|
|
+ [[connectDeviceManager shareInstance] getThridMsgBySN:snStr needReconnect:YES didNetEnd:^(NSInteger didSuc) {
|
|
|
+ }];
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //[[connectDeviceManager shareInstance] tryReconnectFun];
|
|
|
+// [self showNewIndicator];
|
|
|
+// reConnectAccount = 0;
|
|
|
+// [self tryAgain];
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark 重启云机
|
|
|
+- (void)needToRebootFun
|
|
|
+{
|
|
|
+ [[webSocketManager shareInstance] needToRebootFun];
|
|
|
+
|
|
|
+ [self startForceStartTimerFun];
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark 启动timer 秒后检查是否软件重启成功
|
|
|
+- (void)startForceStartTimerFun
|
|
|
+{
|
|
|
+ if(forceStartTimer){
|
|
|
+ [forceStartTimer invalidate];
|
|
|
+ forceStartTimer = nil;
|
|
|
+ }
|
|
|
+
|
|
|
+ forceStartTimer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(gotoUpdateForceStartFun) userInfo:nil repeats:NO];
|
|
|
+ [[NSRunLoop currentRunLoop] addTimer:forceStartTimer forMode:NSRunLoopCommonModes];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)gotoUpdateForceStartFun
|
|
|
+{
|
|
|
+ [self updateForceStartFun];
|
|
|
+
|
|
|
+ KWeakSelf
|
|
|
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(30 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
|
+ //[weakSelf reconnectDevice];
|
|
|
+ [[webSocketManager shareInstance] WebSocketNeedRelinkFun];
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark 需要强制重启
|
|
|
+- (void)updateForceStartFun{
|
|
|
+
|
|
|
+ NSString* curSn = [connectDeviceManager shareInstance].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
|