|
|
@@ -0,0 +1,583 @@
|
|
|
+//
|
|
|
+// webSocketManager.m
|
|
|
+// 双子星云手机
|
|
|
+//
|
|
|
+// Created by xd h on 2024/6/20.
|
|
|
+//
|
|
|
+
|
|
|
+#import "webSocketManager.h"
|
|
|
+
|
|
|
+@interface webSocketManager ()
|
|
|
+{
|
|
|
+ NSMutableArray *commandSendCheckArr;//需要检测任务是否发出的的指令
|
|
|
+}
|
|
|
+
|
|
|
+@property(copy,nonatomic)NSString *curIp;
|
|
|
+/**定时器计数*/
|
|
|
+@property (nonatomic, assign) NSInteger webSocketTime;
|
|
|
+/**定时器计数 任务检测*/
|
|
|
+@property (nonatomic, assign) NSInteger webSocketTaskTime;
|
|
|
+@property (nonatomic, copy) NSTimer *timer; // 定时器-控制按钮
|
|
|
+//第一次链接设备 要发送指令信息 实现单点登录
|
|
|
+@property (nonatomic, assign)BOOL didSendfristMsg;
|
|
|
+
|
|
|
+@end
|
|
|
+
|
|
|
+
|
|
|
+@implementation webSocketManager
|
|
|
+static webSocketManager *webSocketManagerInstance = nil;
|
|
|
++(webSocketManager *)shareInstance;
|
|
|
+{
|
|
|
+ static dispatch_once_t onceToken;
|
|
|
+
|
|
|
+ dispatch_once(&onceToken, ^{
|
|
|
+ webSocketManagerInstance = [[webSocketManager alloc] init];
|
|
|
+ });
|
|
|
+
|
|
|
+ return webSocketManagerInstance;
|
|
|
+}
|
|
|
+
|
|
|
+- (void)initOtherFun
|
|
|
+{
|
|
|
+ if(_timer){
|
|
|
+ //[_timer invalidate];
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ _timer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(timerChange) userInfo:nil repeats:YES];
|
|
|
+ [[NSRunLoop currentRunLoop] addTimer:_timer forMode:NSRunLoopCommonModes];
|
|
|
+
|
|
|
+ commandSendCheckArr = [NSMutableArray new];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)opencommandChannelManagerrc_openURL
|
|
|
+{
|
|
|
+ if(self.commandChannelManager){
|
|
|
+
|
|
|
+ if([self.commandChannelManager rc_socketStatus] == RCSocketCloudPhoneStatusConnected
|
|
|
+ ||[self.commandChannelManager rc_socketStatus] == RCSocketCloudPhoneStatusReceived){
|
|
|
+ //链接中不处理
|
|
|
+ HLog(@"WebSocket 链接时已经存在并且链接中");
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ HLog(@"WebSocket 链接时已经存在并且链接失效");
|
|
|
+ [self.commandChannelManager rc_close];
|
|
|
+
|
|
|
+ self.commandChannelManager = nil;
|
|
|
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
|
+ [self opencommandChannelManagerrc_openURL];
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ KWeakSelf
|
|
|
+ //初始化指令通道
|
|
|
+ self.commandChannelManager = [[RCCommandChannelManager alloc] init];
|
|
|
+
|
|
|
+ NSString *wsPort = @"";
|
|
|
+ if([connectDeviceManager shareInstance].isPingOk
|
|
|
+ && [AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusReachableViaWiFi){
|
|
|
+ _curIp = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.ip;
|
|
|
+ wsPort = @"9300";
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ _curIp = ruiyunlinkIp;
|
|
|
+ wsPort = [[connectDeviceManager shareInstance] tcpPortStr];
|
|
|
+ }
|
|
|
+
|
|
|
+ NSString *instructionsChannelUrl = [NSString stringWithFormat:@"ws://%@:%@/businessChannel",_curIp,wsPort];
|
|
|
+
|
|
|
+ if (instructionsChannelUrl && instructionsChannelUrl.length > 0) { //当都有值才可连接
|
|
|
+ HLog(@"WebSocket11111指令通道连接开始11111 url = %@ ",instructionsChannelUrl);
|
|
|
+ [self.commandChannelManager rc_openURL:instructionsChannelUrl connected:^{
|
|
|
+ HLog(@"WebSocket11111指令通道连接成功11111 url = %@ ",instructionsChannelUrl);
|
|
|
+ if (weakSelf.commandChannelManager.rc_socketStatus == RCSocketCloudPhoneStatusConnected){
|
|
|
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
|
+ [weakSelf initOtherFun];
|
|
|
+ [weakSelf handlAllMsgAfterDidLinkFun];
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } receive:^(id message, FLSocketCloudPhoneReceiveType type) {
|
|
|
+
|
|
|
+ if([message isKindOfClass:[NSData class]] && [message length] == 0){
|
|
|
+ if(type == RCSocketCloudPhoneReceiveTypeForPong)
|
|
|
+ {
|
|
|
+ [weakSelf keepWebSocketOKFun];
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ HLog(@"webSocket指令通道接收消息:------------------\n%@",message);
|
|
|
+
|
|
|
+ if([message isKindOfClass:[NSMutableString class]] || [message isKindOfClass:[NSString class]])
|
|
|
+ {
|
|
|
+ message = [(NSString *)message dataUsingEncoding:(NSUTF8StringEncoding)];
|
|
|
+ }
|
|
|
+
|
|
|
+ NSError *error = nil;
|
|
|
+ NSDictionary *dataDict = [NSJSONSerialization JSONObjectWithData:message options:NSJSONReadingMutableContainers error:&error];
|
|
|
+
|
|
|
+// if(!dataDict){
|
|
|
+// [weakSelf handleDownloadResponseFunBy:message];
|
|
|
+// return;
|
|
|
+// }
|
|
|
+//
|
|
|
+// if(![dataDict isKindOfClass:[NSDictionary class]]){
|
|
|
+// //[__NSCFString allKeys] unrecognized selector sent to ins
|
|
|
+// return;
|
|
|
+// }
|
|
|
+//
|
|
|
+// NSString *messageType = dataDict[@"type"];
|
|
|
+//
|
|
|
+// if ([messageType isEqualToString:@"cutting"]) {
|
|
|
+// //[[iToast makeText:@"复制成功"] show];
|
|
|
+// }
|
|
|
+// else if ([messageType isEqualToString:@"forwardMsgRep"]){/*转发的回复*/
|
|
|
+//
|
|
|
+// cloudPhoneCommonModel *model = [[cloudPhoneCommonModel alloc] initWithDictionary:dataDict error:nil];
|
|
|
+// if(!model){
|
|
|
+// return;
|
|
|
+// }
|
|
|
+//
|
|
|
+// if([model.data.msg isEqualToString:@"only one socket"]){
|
|
|
+// [weakSelf deleteCommandSendTaskFunWith:@"offline_notification"];
|
|
|
+// }
|
|
|
+// }
|
|
|
+// else if ([messageType isEqualToString:@"forwardMsg"]){/*转发*/
|
|
|
+// /*获取指令类型*/
|
|
|
+// NSString *code = nil;
|
|
|
+// if ([[dataDict allKeys] containsObject:@"data"]) {
|
|
|
+// NSDictionary *data = dataDict[@"data"];
|
|
|
+//
|
|
|
+// if([data isKindOfClass:[NSString class]]){
|
|
|
+// NSString * dataStr = (NSString*)data;
|
|
|
+// if([dataStr isEqualToString:@"offline_notification"]){
|
|
|
+// HLog(@"被别人挤下线了");
|
|
|
+// [weakSelf LogoutByOtherFun];
|
|
|
+// }
|
|
|
+//
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// else if ([data isKindOfClass:[NSDictionary class]] && [[data allKeys] containsObject:@"code"]) {
|
|
|
+// code = [data objectForKey:@"code"];
|
|
|
+//
|
|
|
+// if (![code isKindOfClass:[NSString class]]) {
|
|
|
+// code = [NSString stringWithFormat:@"%ld",[code integerValue]];
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// /*获取用户名*/
|
|
|
+// NSString *useName = nil;
|
|
|
+// if ([[dataDict allKeys] containsObject:@"data"]) {
|
|
|
+// NSDictionary *data = dataDict[@"data"];
|
|
|
+// if ([[data allKeys] containsObject:@"userName"]) {
|
|
|
+// useName = [data objectForKey:@"userName"];
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// if ([code isEqualToString:@"phoneSizeChange"]){/*分辨率改变*/
|
|
|
+// if ([[dataDict allKeys] containsObject:@"data"]) {
|
|
|
+// NSDictionary *data = dataDict[@"data"];
|
|
|
+// if ([[data allKeys] containsObject:@"width"]) {
|
|
|
+// ksharedAppDelegate.couldPhone_W_PHONE = [[data objectForKey:@"width"] integerValue];
|
|
|
+// }
|
|
|
+// if ([[data allKeys] containsObject:@"height"]) {
|
|
|
+// ksharedAppDelegate.couldPhone_H_PHONE = [[data objectForKey:@"height"] integerValue];
|
|
|
+// }
|
|
|
+//
|
|
|
+// if (ksharedAppDelegate.couldPhone_W_PHONE > ksharedAppDelegate.couldPhone_H_PHONE) {
|
|
|
+// CGFloat temp = ksharedAppDelegate.couldPhone_W_PHONE;
|
|
|
+// ksharedAppDelegate.couldPhone_W_PHONE = ksharedAppDelegate.couldPhone_H_PHONE;
|
|
|
+// ksharedAppDelegate.couldPhone_H_PHONE = temp;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// else if ([messageType isEqualToString:@"getPhoneSize"] || [messageType isEqualToString:@"setPhoneSize"]){
|
|
|
+// NSString *sn = nil;
|
|
|
+// if ([[dataDict allKeys] containsObject:@"data"]) {
|
|
|
+// NSDictionary *data = dataDict[@"data"];
|
|
|
+//
|
|
|
+// if ([[data allKeys] containsObject:@"status"]) {
|
|
|
+// NSInteger status = [[data objectForKey:@"status"] integerValue];
|
|
|
+//
|
|
|
+// if (status == 0) {/*不是当前设备直接返回*/
|
|
|
+// if ([[data allKeys] containsObject:@"width"]) {
|
|
|
+// ksharedAppDelegate.couldPhone_W_PHONE = [[data objectForKey:@"width"] integerValue];
|
|
|
+// }
|
|
|
+// if ([[data allKeys] containsObject:@"height"]) {
|
|
|
+// ksharedAppDelegate.couldPhone_H_PHONE = [[data objectForKey:@"height"] integerValue];
|
|
|
+// }
|
|
|
+//
|
|
|
+// if (ksharedAppDelegate.couldPhone_W_PHONE > ksharedAppDelegate.couldPhone_H_PHONE) {
|
|
|
+// CGFloat temp = ksharedAppDelegate.couldPhone_W_PHONE;
|
|
|
+// ksharedAppDelegate.couldPhone_W_PHONE = ksharedAppDelegate.couldPhone_H_PHONE;
|
|
|
+// ksharedAppDelegate.couldPhone_H_PHONE = temp;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+//
|
|
|
+// }
|
|
|
+// else if ([messageType isEqualToString:@"sync_wifi"]){
|
|
|
+// [weakSelf sync_wifiBackHandleFun];
|
|
|
+// }
|
|
|
+// else if ([messageType isEqualToString:@"reProduceText"]){
|
|
|
+// if ([[dataDict allKeys] containsObject:@"data"]) {
|
|
|
+// NSDictionary *data = dataDict[@"data"];
|
|
|
+//
|
|
|
+// if ([[data allKeys] containsObject:@"text"]) {
|
|
|
+// NSString *pasteboardStr = [data objectForKey:@"text"];
|
|
|
+// UIPasteboard* pasteboard = [UIPasteboard generalPasteboard];
|
|
|
+// pasteboard.string = pasteboardStr;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// else if ([messageType isEqualToString:@"downAdnInstallRep"]){
|
|
|
+// if ([[dataDict allKeys] containsObject:@"data"]) {
|
|
|
+// NSDictionary *data = dataDict[@"data"];
|
|
|
+//
|
|
|
+// if ([[data allKeys] containsObject:@"status"]) {
|
|
|
+// NSString *status = [data objectForKey:@"status"];
|
|
|
+// if ([status isEqualToString:@"1"]) {
|
|
|
+// mainBlock(^{
|
|
|
+// // [[iToast makeText:@"App下载完成"] show];
|
|
|
+// });
|
|
|
+// }else if ([status isEqualToString:@"0"]){
|
|
|
+// mainBlock(^{
|
|
|
+// //[[iToast makeText:@"App下载中"] show];
|
|
|
+// });
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// else if ([messageType isEqualToString:@"shakeit"]){
|
|
|
+// HLog(@"\n-----摇一摇成功------");
|
|
|
+// }else if ([messageType isEqualToString:@"keyboardFeedbackBean"]){/*调起键盘*/
|
|
|
+// [weakSelf keyboardFeedbackBeanFun];
|
|
|
+// }else if ([messageType isEqualToString:@"FileRandomReady"]
|
|
|
+// ||[messageType isEqualToString:@"FilePartReady"]
|
|
|
+// ){/*申请文件上传得到答复*/
|
|
|
+// [weakSelf applyUploadFileServiceResponseFun:dataDict];
|
|
|
+// }
|
|
|
+// else if ([messageType isEqualToString:@"uploadFileRandomRet"]
|
|
|
+// ||[messageType isEqualToString:@"uploadFilePartRet"]
|
|
|
+// ){/*文件上传得到答复*/
|
|
|
+// [weakSelf upLoadFileFunServiceResponseFun:dataDict];
|
|
|
+// }
|
|
|
+// else if ([messageType isEqualToString:@"backUpFileRandomReady"]
|
|
|
+// ||[messageType isEqualToString:@"backUpPartReady"]
|
|
|
+// ){/*文件备份得到答复*/
|
|
|
+// [weakSelf applyBackupsFileServiceResponseFun:dataDict];
|
|
|
+// }
|
|
|
+// else if ([messageType isEqualToString:@"backUpFileRandomRet"]
|
|
|
+// ||[messageType isEqualToString:@"backUpFilePartRet"]){/*文件备份得到答复*/
|
|
|
+// [weakSelf backupsFileFunServiceResponseFun:dataDict];
|
|
|
+// }
|
|
|
+// else if ([messageType isEqualToString:@"getBaseInfo"]){/*获取云机的基本信息*/
|
|
|
+// [weakSelf getCouldPhoneBaseInfoResponseFun:dataDict];
|
|
|
+// }
|
|
|
+// else if ([messageType isEqualToString:@"getSysInfo"]){/*获取云机的系统信息*/
|
|
|
+// [weakSelf getCouldPhoneSysInfoResponseFun:dataDict];
|
|
|
+// }
|
|
|
+// else if ([messageType isEqualToString:@"TvStatus"]){/*获取TV投屏信息*/
|
|
|
+// [weakSelf getCouldPhoneTvStatusResponseFun:dataDict];
|
|
|
+// }
|
|
|
+// else if ([messageType isEqualToString:@"reboot"]){/*重启*/
|
|
|
+// [weakSelf stopForceStartTimerFun];
|
|
|
+// }
|
|
|
+// else if ([messageType isEqualToString:@"mkdir"]){/*创建文件夹*/
|
|
|
+// [weakSelf createFolderResponseFun:dataDict];
|
|
|
+// }
|
|
|
+// else if ([messageType isEqualToString:@"getBackupPath"]){/*创建文件夹*/
|
|
|
+// [weakSelf getFolderListResponseFun:dataDict];
|
|
|
+// }
|
|
|
+// else if ([messageType isEqualToString:@"search"]){/*创建文件夹*/
|
|
|
+// [weakSelf searchFileListResponseFun:dataDict];
|
|
|
+// }
|
|
|
+// else if ([messageType isEqualToString:@"getExtraFiles"]){/*创建文件夹*/
|
|
|
+// [weakSelf getExtraFilesResponseFun:dataDict];
|
|
|
+// }
|
|
|
+// else if ([messageType isEqualToString:@"extraMediaEvent"]){/*磁盘插拔*/
|
|
|
+// [weakSelf getExtraMediaEventResponseFun:dataDict];
|
|
|
+// [weakSelf getExtraFilesListFun];
|
|
|
+// }
|
|
|
+// else if ([messageType isEqualToString:@"reset"]){/**/
|
|
|
+// [weakSelf deleteCommandSendTaskFunWith:@"reset"];
|
|
|
+// }
|
|
|
+
|
|
|
+ } failure:^(NSError *error) {
|
|
|
+ ksharedAppDelegate.isWebSockLinkOKAginType = NO;
|
|
|
+// [self showNetErrorAlertFun:2];
|
|
|
+// [self WebSocketNeedRelinkFun];
|
|
|
+ }];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)keepWebSocketOKFun
|
|
|
+{
|
|
|
+ self.webSocketTime = 0;
|
|
|
+}
|
|
|
+
|
|
|
+- (void)WebSocketNeedRelinkFun
|
|
|
+{
|
|
|
+ self.webSocketTime = 0;
|
|
|
+
|
|
|
+ if(self.commandChannelManager){
|
|
|
+ [self opencommandChannelManagerrc_openURL];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)timerChange {
|
|
|
+
|
|
|
+
|
|
|
+ //处理websockt是否断开
|
|
|
+ self.webSocketTime += 2;
|
|
|
+
|
|
|
+ //处理其他任务
|
|
|
+ self.webSocketTaskTime += 2;
|
|
|
+
|
|
|
+ if(self.webSocketTime > 8)
|
|
|
+ {
|
|
|
+ [self WebSocketNeedRelinkFun];
|
|
|
+ }
|
|
|
+
|
|
|
+ if(self.webSocketTaskTime > 5)
|
|
|
+ {
|
|
|
+ self.webSocketTaskTime = 0;
|
|
|
+ [self checkAllTaskFun];
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)checkAllTaskFun
|
|
|
+{
|
|
|
+ if([self.commandChannelManager rc_socketStatus] == RCSocketCloudPhoneStatusConnected
|
|
|
+ ||[self.commandChannelManager rc_socketStatus] == RCSocketCloudPhoneStatusReceived){
|
|
|
+ HLog(@"WebSocket 链接正常");
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ HLog(@"WebSocket 链接异常:%ld",[self.commandChannelManager rc_socketStatus]);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //处理相册备份
|
|
|
+ [[backupsFileManager shareInstance] checkReBackupsFileFun];
|
|
|
+
|
|
|
+ [[uploadFileManager shareInstance] checkReUploadFileFun];
|
|
|
+ [[downloadManager shareInstance] checkReDownloadFileFun];
|
|
|
+
|
|
|
+ [[downloadThumbnailManager shareInstance] checkReDownloadThumbnailFileFun];
|
|
|
+
|
|
|
+ [self checkCommandSendTaskFun];
|
|
|
+
|
|
|
+ if([AudioSessionObject shareManager].isBackgroundType){
|
|
|
+ [self checkFileTransfeTaskFun];
|
|
|
+ }
|
|
|
+
|
|
|
+ HLog(@"checkAllTaskFun");
|
|
|
+}
|
|
|
+
|
|
|
+//检测是否正在进行的文件传输任务
|
|
|
+- (void)checkFileTransfeTaskFun
|
|
|
+{
|
|
|
+
|
|
|
+ BOOL isBackupsingType = [[backupsFileManager shareInstance] checkBackupsingFun];
|
|
|
+ BOOL isUploadingType = [[uploadFileManager shareInstance] checkUploadingFun];
|
|
|
+ BOOL isDownloadingType = [[downloadManager shareInstance] checkDownloadingFun];
|
|
|
+ BOOL isBackground = [HWDataManager getBoolWithKey:stringKeyAddSn(Const_file_Transfe_working_background)];
|
|
|
+
|
|
|
+ if ((isBackupsingType || isUploadingType || isDownloadingType) && isBackground) {
|
|
|
+ HLog(@"后台保活中");
|
|
|
+ [cachesFileManager writeLogsWithMsg:@"Background working"];
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ HLog(@"停止后台保活");
|
|
|
+ [cachesFileManager writeLogsWithMsg:@"stop Background working"];
|
|
|
+ [[AudioSessionObject shareManager] stopBackgroundActiveFun];
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+-(void)checkCommandSendTaskFun
|
|
|
+{
|
|
|
+ if(commandSendCheckArr && commandSendCheckArr.count >0){
|
|
|
+ for (commandSendCheckModel *model in commandSendCheckArr) {
|
|
|
+ if(model.reSendNum < 3){
|
|
|
+ model.reSendNum ++;
|
|
|
+ if(model.commandStr){
|
|
|
+ [self send_data:model.commandStr];
|
|
|
+
|
|
|
+ HLog(@"\n\n\n任务重发 重发次数:%ld 指令:%@\n\n\n",model.reSendNum,model.commandStr);
|
|
|
+ }
|
|
|
+
|
|
|
+// if([model.type isEqualToString:@"offline_notification"]){
|
|
|
+// model.reSendNum = 1;//只要不收到
|
|
|
+// }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)send_data:(NSString *)dataStr
|
|
|
+{
|
|
|
+ [self.commandChannelManager rc_sendData:dataStr];
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark 盒子链接成功后需要处理的各种各样事情
|
|
|
+- (void)handlAllMsgAfterDidLinkFun
|
|
|
+{
|
|
|
+ ksharedAppDelegate.isWebSockLinkOKAginType = YES;
|
|
|
+
|
|
|
+ //获取云机尺寸 兼容 720*1080 &1080*1920 不同分辨率的展示和触控
|
|
|
+ NSString *getPhoneSizeStr = [RCCommandHelp getPhoneSizecommand];
|
|
|
+ [self send_data:getPhoneSizeStr];
|
|
|
+
|
|
|
+ //判断是否为需要改机
|
|
|
+ BOOL isNeedRandomChangeParams = [HWDataManager getBoolWithKey:Const_need_random_Change_Params];
|
|
|
+ if(isNeedRandomChangeParams)
|
|
|
+ {
|
|
|
+ NSString *commondStr = @"{\"type\":\"randomChangeParams\"}";
|
|
|
+ [self send_data:commondStr];
|
|
|
+
|
|
|
+ [HWDataManager setBoolWithKey:Const_need_random_Change_Params value:NO];
|
|
|
+ }
|
|
|
+
|
|
|
+ [self fristConnectNeedGiveAMsgFun];
|
|
|
+
|
|
|
+ [self updateCopydata];
|
|
|
+
|
|
|
+ // 报链接失败 后面又连接上了
|
|
|
+// if(linkFailAlretVC && linkFailAlretVC.view.tag == 2){
|
|
|
+// mainBlock(^{
|
|
|
+// [self->linkFailAlretVC dismissViewControllerAnimated:YES completion:^{
|
|
|
+//
|
|
|
+// }];
|
|
|
+// self->linkFailAlretVC = nil;
|
|
|
+// });
|
|
|
+// }
|
|
|
+
|
|
|
+ //处理相册备份
|
|
|
+ [[backupsFileManager shareInstance] AutohandlePhotosBackupsFun];
|
|
|
+
|
|
|
+ //获取磁盘外挂
|
|
|
+ [self getExtraFilesListFun];
|
|
|
+
|
|
|
+ //self.webSocketConcentTime = [iTools getNowTimeStamp];
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark 盒子第一次连接成功 给ws发送信息 单点登录 把其他账号挤下去
|
|
|
+- (void)fristConnectNeedGiveAMsgFun{
|
|
|
+
|
|
|
+ if(!_didSendfristMsg )
|
|
|
+ {
|
|
|
+ NSString *commondStr3 = @"{\"type\":\"getSysInfo\"}";
|
|
|
+ [self send_data:commondStr3];
|
|
|
+
|
|
|
+// NSString *commondStr = @"{\"type\":\"forwardMsg\",\"data\":\"offline_notification\"}";
|
|
|
+// [self send_data:commondStr];
|
|
|
+// [self addCommandSendTaskFunWithType:@"offline_notification" WithCommandStr:commondStr];
|
|
|
+
|
|
|
+ _didSendfristMsg = true;
|
|
|
+
|
|
|
+ [self getPreferredLanguage];
|
|
|
+
|
|
|
+ NSString *commondStr2 = @"{\"type\":\"TvStatus\"}";
|
|
|
+ [self send_data:commondStr2];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark 语言和市区 同步云机
|
|
|
+-(void)getPreferredLanguage
|
|
|
+{//{"data":{"language":"zh-CN","timeZone":"Etc/GMT+8"},"type":"setLanguages"}
|
|
|
+ // iOS 获取设备当前语言的代码
|
|
|
+ NSString *preferredLanguage = [[[NSBundle mainBundle] preferredLocalizations] firstObject];
|
|
|
+ HLog(@"当前语言:%@", preferredLanguage);
|
|
|
+
|
|
|
+ //en-US 英文 ja-JP 日文
|
|
|
+
|
|
|
+ NSArray *arLanguages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];
|
|
|
+ NSLog(@"arLanguages:%@",arLanguages);
|
|
|
+ ///获取设备当前地区的代码和APP语言环境
|
|
|
+ NSString *languageCode = [NSLocale preferredLanguages][0];
|
|
|
+
|
|
|
+
|
|
|
+ //目前支持 中文(简体 繁体) 英文 日语
|
|
|
+ if([languageCode rangeOfString:@"zh-Hans"].location != NSNotFound)
|
|
|
+ {
|
|
|
+ preferredLanguage = @"zh-CN";
|
|
|
+ }
|
|
|
+ else if([languageCode rangeOfString:@"zh-Hant"].location != NSNotFound)
|
|
|
+ {
|
|
|
+ preferredLanguage = @"zh-HK";
|
|
|
+ }
|
|
|
+ else if([languageCode rangeOfString:@"ja-"].location != NSNotFound)
|
|
|
+ {
|
|
|
+ preferredLanguage = @"ja-JP";
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ preferredLanguage = @"en-US";
|
|
|
+ }
|
|
|
+
|
|
|
+// if([languageCode rangeOfString:preferredLanguage].location != NSNotFound){
|
|
|
+// preferredLanguage = languageCode;
|
|
|
+// }
|
|
|
+// else{
|
|
|
+// preferredLanguage = @"en-US";
|
|
|
+// }
|
|
|
+
|
|
|
+ NSString*gmtStr = [self UTCOffset];
|
|
|
+ HLog(@"%@",gmtStr);
|
|
|
+// //获取名字,如“GMT+08:00
|
|
|
+
|
|
|
+ NSString *commondStr = [NSString stringWithFormat:@"{\"type\":\"setLanguages\",\"data\":{\"language\":\"%@\",\"timeZone\":\"%@\"}}",preferredLanguage,gmtStr];
|
|
|
+
|
|
|
+ [self send_data:commondStr];
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+-(NSString *)UTCOffset {
|
|
|
+ NSTimeZone *localTZ = [NSTimeZone localTimeZone];
|
|
|
+ float offset = localTZ.secondsFromGMT/3600.0;
|
|
|
+ if(offset > 0){
|
|
|
+ return [NSString stringWithFormat:@"Etc/GMT+%g",offset];
|
|
|
+ }
|
|
|
+ return [NSString stringWithFormat:@"Etc/GMT%g",offset];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)updateCopydata{
|
|
|
+ UIPasteboard* pasteboard = [UIPasteboard generalPasteboard];
|
|
|
+ NSString *str = [pasteboard string];
|
|
|
+
|
|
|
+ HLog(@"__________%s______%@____",__func__,str);
|
|
|
+
|
|
|
+ if ([str rangeOfString:@"CVLUSTERS_NOUSE_"].location != NSNotFound)
|
|
|
+ {
|
|
|
+ str = nil;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (str && str.length >0)
|
|
|
+ {
|
|
|
+ //HLog(@"hxd111 cutting %@",str);
|
|
|
+ /*发送数据*/
|
|
|
+ NSString *dataStr = [RCCommandHelp commandCuttingWithContent:str];
|
|
|
+ [self.commandChannelManager rc_sendData:dataStr];
|
|
|
+ //pasteboard.string = @"";
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark 获取外挂产品
|
|
|
+- (void)getExtraFilesListFun
|
|
|
+{
|
|
|
+ NSString *ExtraCommondStr = [RCCommandHelp getExtraFilesList];
|
|
|
+ [self send_data:ExtraCommondStr];
|
|
|
+}
|
|
|
+@end
|