PlayerViewController+otherDelegate.mm 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. //
  2. // PlayerViewController+otherDelegate.m
  3. // 隐私保护
  4. //
  5. // Created by xd h on 2023/10/13.
  6. //
  7. #import "PlayerViewController+otherDelegate.h"
  8. #import "RCCommandHelp.h"
  9. #import "couldPhoneBaseInfoModel.h"
  10. #import "cachesFileManager.h"
  11. #import "couldphoneSysInfoModel.h"
  12. #import "TvStatusModel.h"
  13. #import "HWVersionModel.h"
  14. #import <MJExtension.h>
  15. #import "HaveNewVersionView.h"
  16. #import "connectDeviceManager.h"
  17. #import "PlayerViewController+downloadFile.h"
  18. #import "downloadManager.h"
  19. #import "uploadFileManager.h"
  20. #import "cloudPhoneExtraFileListModel.h"
  21. #import "AppDelegate.h"
  22. #import "cachesFileManager.h"
  23. #import "extraMediaEventModel.h"
  24. #import "USBInsertPopView.h"
  25. #import "commandSendCheckModel.h"
  26. @implementation PlayerViewController (otherDelegate)
  27. #pragma mark ComontAlretViewControllerDelegate
  28. - (void)CommonAlertokBtnClickPressed{
  29. //HLog("11111");
  30. if(self->logoutAlertVC){
  31. self->logoutAlertVC = nil;
  32. }
  33. self.isLoginAgainType = YES;
  34. [[NSNotificationCenter defaultCenter] postNotificationName:lockBypwdNotification object:nil];
  35. }
  36. - (void)CommonAlertCancelBtnClickPressed{
  37. HLog("强制退出app");
  38. exit(0);/*强制退出app*/
  39. }
  40. - (void)checkVersionFun
  41. {
  42. [self getVersion];
  43. }
  44. #pragma mark- 网络请求
  45. - (void)getVersion {
  46. NSMutableDictionary *paraDict = [NSMutableDictionary dictionary];
  47. [paraDict setValue:@"ios" forKey:@"type"];
  48. [paraDict setValue:@"skyworth" forKey:@"source"];
  49. [[netWorkManager shareInstance] CommonGetWithCallBackCode:upgradeNewVersion Parameters:paraDict success:^(id _Nonnull responseObject) {
  50. //HLog(@"%@", responseObject);
  51. SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
  52. if (model.status == 0) {
  53. HWVersionModel *model = [HWVersionModel mj_objectWithKeyValues:responseObject[@"data"]];
  54. [self checkVersion:model];
  55. }
  56. else
  57. {
  58. //[[iToast makeText:model.msg] show];
  59. }
  60. } failure:^(NSError * _Nonnull error) {
  61. HLog(@"%@", error);
  62. }];
  63. }
  64. - (void)checkVersion:(HWVersionModel*)versionModel {
  65. // NSString *currentVersion = [NSBundle mainBundle].infoDictionary[@"CFBundleVersion"];
  66. NSString *currentVersion = [NSBundle mainBundle].infoDictionary[@"CFBundleShortVersionString"];
  67. NSString *newVersion = [versionModel.versionNumber stringByReplacingOccurrencesOfString:@"v" withString:@""]; //去掉v
  68. // HLog(@"%@---%@", newVersion, currentVersion);
  69. if ([currentVersion compare:newVersion options:NSNumericSearch] == NSOrderedSame) { // 本地版本号 == 服务器版本号
  70. }else if ([currentVersion compare:newVersion options:NSNumericSearch] == NSOrderedDescending) { // 本地版本号 > 服务器版本号 (异常情况)
  71. [HWDataManager setBoolWithKey:Const_haveVersion value:NO];
  72. }else { // 本地版本号 < 服务器版本号 (有新版本)
  73. [self showNewVersion:versionModel];
  74. [HWDataManager setBoolWithKey:Const_haveVersion value:YES];
  75. };
  76. }
  77. #pragma mark 需要强制重启
  78. - (void)updateForceStartFun{
  79. NSString* curSn = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.changeSn;
  80. NSMutableDictionary *paraDict = [NSMutableDictionary dictionary];
  81. [paraDict setValue:curSn forKey:@"sn"];
  82. [paraDict setValue:[NSNumber numberWithBool:YES] forKey:@"isForceStart"];
  83. [[netWorkManager shareInstance] CommonPostCallBackCode:updateForceStart Parameters:paraDict success:^(id _Nonnull responseObject) {
  84. SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
  85. if (model.status == 0) {
  86. }
  87. else
  88. {
  89. }
  90. } failure:^(NSError * _Nonnull error) {
  91. HLog(@"%@", error);
  92. }];
  93. }
  94. - (void)showNewVersion:(HWVersionModel*)versionModel {
  95. HaveNewVersionView *haveNewVersionView = [HaveNewVersionView shardInstance];
  96. if (haveNewVersionView.isShow) {
  97. return;
  98. }
  99. haveNewVersionView.versionModel = versionModel;
  100. haveNewVersionView.isContinueCheckAlert = NO; // 是否继续走下一步弹窗检测流程
  101. [haveNewVersionView setBackgroundColor:RGBACOLOR(0, 0, 0, 0.5)];
  102. [[iTools getKeyWindow] addSubview:haveNewVersionView];
  103. haveNewVersionView.isShow = YES;
  104. if(!versionModel.necessary){
  105. haveNewVersionView.deleteBtn.hidden = NO;
  106. }
  107. [haveNewVersionView mas_makeConstraints:^(MASConstraintMaker *make) {
  108. make.top.mas_equalTo(0);
  109. make.left.mas_equalTo(0);
  110. make.right.mas_equalTo(0);
  111. make.bottom.mas_equalTo(0);
  112. }];
  113. haveNewVersionView.alpha = 0.0;
  114. [UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^ {
  115. haveNewVersionView.alpha = 1.0;
  116. KyoLog(@"in animate start");
  117. } completion:^(BOOL finished) {
  118. KyoLog(@"in animate completion");
  119. }];
  120. }
  121. - (void)getCouldPhoneBaseInfoResponseFun:(NSDictionary *)dataDict
  122. {
  123. couldPhoneBaseInfoModel *model = [[couldPhoneBaseInfoModel alloc] initWithDictionary:dataDict error:nil];
  124. [[NSNotificationCenter defaultCenter] postNotificationName:getCouldPhoneBaseInfoNotification object:model];
  125. }
  126. - (void)getCouldPhoneSysInfoResponseFun:(NSDictionary *)dataDict{
  127. couldphoneSysInfoModel *model = [[couldphoneSysInfoModel alloc] initWithDictionary:dataDict error:nil];
  128. [[NSNotificationCenter defaultCenter] postNotificationName:getCouldPhoneSysInfoNotification object:model];
  129. // NSString * predatestr = [HWDataManager getObjectWithKey:Const_did_show_image_version_date];
  130. //
  131. // NSString *datestr = [iTools getNowDateString];
  132. //
  133. // if(predatestr && [predatestr isEqualToString:datestr]){
  134. // return;
  135. // }
  136. NSString *hostImgVer = model.data.data.hostImgVer;
  137. NSString *MyNewVersion = model.data.data.MyNewVersion;
  138. //test code
  139. // hostImgVer = @"1.2.3";
  140. // MyNewVersion = @"1.2.0";
  141. //判断当前版本号 待更新版本
  142. if (!hostImgVer || hostImgVer.length < 3
  143. ||!MyNewVersion || MyNewVersion.length < 3) {
  144. //[self showImageViewRenewTipViewFun];
  145. return;
  146. }
  147. NSArray *versionArr = [hostImgVer componentsSeparatedByString:@"."];
  148. NSArray *MyNewVersionArr = [MyNewVersion componentsSeparatedByString:@"."];
  149. NSInteger versionArrCount = versionArr.count;
  150. NSInteger MyNewVersionArrCount = MyNewVersionArr.count;
  151. NSInteger maxCount = versionArrCount < MyNewVersionArrCount ? versionArrCount:MyNewVersionArrCount;
  152. BOOL isNeedShowType = NO;
  153. //判断是否要更新镜像框
  154. if(maxCount > 0){
  155. for (int i=0; i<maxCount; i++) {
  156. NSString * numberStr1 = versionArr[i];
  157. NSString * numberStr2 = MyNewVersionArr[i];
  158. if(numberStr2.intValue > numberStr1.intValue){
  159. isNeedShowType =YES;
  160. break;
  161. }
  162. }
  163. }
  164. if(isNeedShowType){
  165. [self showImageViewRenewTipViewFun];
  166. }
  167. //是否禁用文件传输 (1.3以及以上的镜像可以使用文件传输)
  168. if(versionArr.count >= 3)
  169. {
  170. NSString * oneStr = versionArr[0];
  171. NSString * twoStr = versionArr[1];
  172. //NSString * threeStr = versionArr[2];
  173. if(oneStr.integerValue <=1 && twoStr.integerValue <=2){//禁用
  174. ksharedAppDelegate.DisabledFileTransferType = YES;
  175. if(MyNewVersionArr.count >= 3)
  176. {
  177. NSString * newOneStr = MyNewVersionArr[0];
  178. NSString * newTwoStr = MyNewVersionArr[1];
  179. NSString * newThreeStr = MyNewVersionArr[2];
  180. if(newOneStr.integerValue >=1 && newTwoStr.integerValue >=3 && newThreeStr.integerValue >= 1){
  181. ksharedAppDelegate.isImageNewFor130 = YES;
  182. }
  183. else{
  184. ksharedAppDelegate.isImageNewFor130 = NO;
  185. }
  186. }
  187. }
  188. else{
  189. ksharedAppDelegate.DisabledFileTransferType = NO;
  190. }
  191. }
  192. }
  193. - (void)getCouldPhoneTvStatusResponseFun:(NSDictionary *)dataDict
  194. {
  195. TvStatusModel *model = [[TvStatusModel alloc] initWithDictionary:dataDict error:nil];
  196. [[NSNotificationCenter defaultCenter] postNotificationName:getCouldPhoneTvStatusNotification object:model];
  197. if(![model.msg containsString:@"PushStreamBActivity"])
  198. {
  199. return;
  200. }
  201. UIViewController*topVc = self.navigationController.viewControllers.lastObject;
  202. if([topVc isKindOfClass:[PlayerViewController class]]){
  203. [[iToast makeText:NSLocalizedString(@"tv_p2p_ing",nil)] show];
  204. }
  205. }
  206. - (void)showImageViewRenewTipViewFun
  207. {
  208. imageVersionRenewTipView * RenewTipView = [[imageVersionRenewTipView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H)];
  209. [self.view addSubview:RenewTipView];
  210. [self.view bringSubviewToFront:RenewTipView];
  211. }
  212. - (void)createFolderBeginNotFun:(NSNotification *)notification
  213. {
  214. NSString *folderName = [notification object];
  215. if(folderName && folderName.length >0){
  216. NSString * commandStr = [RCCommandHelp applyForCreateFolderwithFolderName:folderName];
  217. [self.commandChannelManager rc_sendData:commandStr];
  218. }
  219. }
  220. - (void)createFolderResponseFun:(NSDictionary *)dataDict
  221. {
  222. couldPhoneCommonModel *model = [[couldPhoneCommonModel alloc] initWithDictionary:dataDict error:nil];
  223. if(model){
  224. NSNumber *curNum = [NSNumber numberWithInteger:model.status];
  225. [[NSNotificationCenter defaultCenter] postNotificationName:createFolderDoneNotification object:curNum];/*发送通知*/
  226. }
  227. }
  228. - (void)getFolderListBeginNotFun:(NSNotification *)notification
  229. {
  230. NSString * commandStr = [RCCommandHelp getCreateFolderList];
  231. [self.commandChannelManager rc_sendData:commandStr];
  232. }
  233. - (void)getFolderListResponseFun:(NSDictionary *)dataDict
  234. {
  235. [[NSNotificationCenter defaultCenter] postNotificationName:getFolderListDoneNotification object:dataDict];/*发送通知*/
  236. }
  237. - (void)searchFileListBeginFun:(NSNotification *)notification
  238. {
  239. NSMutableDictionary *objectDict = [notification object];
  240. NSNumber *curNum = @1;
  241. if ([[objectDict allKeys] containsObject:@"type"]) {
  242. curNum = [objectDict objectForKey:@"type"];
  243. }
  244. NSString *pathStr = @"";
  245. if ([[objectDict allKeys] containsObject:@"path"]) {
  246. pathStr = [objectDict objectForKey:@"path"];
  247. }
  248. NSString *fileType = @"video";
  249. if(curNum.boolValue)
  250. {
  251. fileType = @"jpg";
  252. }
  253. NSString * commandStr = [RCCommandHelp searchCouldPhoneFilewithType:fileType withPath:pathStr];
  254. [self.commandChannelManager rc_sendData:commandStr];
  255. }
  256. - (void)searchFileListResponseFun:(NSDictionary *)dataDict
  257. {
  258. [[NSNotificationCenter defaultCenter] postNotificationName:searchFileListDoneNotification object:dataDict];/*发送通知*/
  259. }
  260. // NSData转int
  261. - (int)data2Int:(NSData *)data{
  262. Byte *byte = (Byte *)[data bytes];
  263. // 有大小端模式问题?
  264. return (byte[0] << 24) + (byte[1] << 16) + (byte[2] << 8) + (byte[3]);
  265. }
  266. - (void)handleDownloadResponseFunBy:(id)message
  267. {
  268. NSData *curData = (NSData *)message;
  269. // if(curData.length < 20){
  270. // return;
  271. // }
  272. //head
  273. NSData *headData = [curData subdataWithRange:NSMakeRange(0, 1)];
  274. char head = 0;//104;
  275. [headData getBytes:&head length:sizeof(head)];
  276. //HLog(@"head: %d",head);
  277. //msgType 0x11(17)
  278. NSData *msgTypeData = [curData subdataWithRange:NSMakeRange(1, 1)];
  279. char msgType = 0;
  280. [msgTypeData getBytes:&msgType length:sizeof(msgType)];
  281. //HLog(@"msgType: %d",msgType);
  282. //taskId 6位字符串
  283. NSData *taskIdData = [curData subdataWithRange:NSMakeRange(2, 6)];
  284. NSString* taskIdStr = [[NSString alloc] initWithData:taskIdData encoding:NSUTF8StringEncoding];;
  285. HLog(@"taskId: %@",taskIdStr);
  286. if(curData.length <= 15){
  287. HLog(@"消息长度不对不处理");
  288. return;
  289. }
  290. //datalen
  291. NSData *datalenData = [curData subdataWithRange:NSMakeRange(8, 4)];
  292. int datalen = [self data2Int:datalenData];
  293. //HLog(@"datalen: %d",datalen);
  294. //curNum
  295. NSData *curNumData = [curData subdataWithRange:NSMakeRange(12, 4)];
  296. int curNum = [self data2Int:curNumData];;
  297. //HLog(@"curNum: %d",curNum);
  298. //totalNum
  299. NSData *totalNumData = [curData subdataWithRange:NSMakeRange(16, 4)];
  300. int totalNum = [self data2Int:totalNumData];
  301. //HLog(@"totalNum: %d",totalNum);
  302. BOOL isDownloadDone = curNum == totalNum ? YES : NO;
  303. HLog(@"taskUid:%@ curNum:%d totalNum: %d datalen:%d isDownloadDone:%d",taskIdStr,curNum,totalNum,datalen -8,isDownloadDone);
  304. if(curData.length <= 23){
  305. //data 的位置 装 成功或者失败
  306. NSData *failTypeData = [curData subdataWithRange:NSMakeRange(20, 1)];
  307. //0xcc (204)失败 0xcd (205)文件不存在 0xdd (221)完成 0xbb 187 完成
  308. __block Byte failType;
  309. [failTypeData getBytes:&failType length:sizeof(failType)];
  310. if(taskIdStr && [taskIdStr isEqualToString:self.downloadFileTaskUid]){
  311. if(failType == 0xcc || failType == 0xcf){
  312. [[downloadManager shareInstance] DownloadFileFailOneFileFun];
  313. }
  314. else if(failType == 0xcd ){
  315. [[downloadManager shareInstance] suspendDownloadFileFun:YES];
  316. NSString *tipStr = NSLocalizedString(@"disk_not_find_tip",nil);
  317. mainBlock(^{
  318. [[iToast makeText:tipStr] show];
  319. });
  320. }
  321. else if(failType == 0xdd || failType == 0xbb){
  322. [self downloadFileFunServiceResponseFun:[NSData new] with:YES];
  323. }
  324. else{
  325. HLog(@"下载数据未知错误");
  326. [[downloadManager shareInstance] DownloadFileFailOneFileFun];
  327. }
  328. }
  329. return;
  330. }
  331. if(curData.length <= (20 + datalen - 8)){
  332. HLog(@"下载数据解析出错了");
  333. return;
  334. }
  335. NSData *fileData = [curData subdataWithRange:NSMakeRange(20, datalen-8)];
  336. if([taskIdStr isEqualToString:self.downloadFileTaskUid]){
  337. [self downloadFileFunServiceResponseFun:fileData with:NO];
  338. }
  339. }
  340. - (void)checkAllTaskFun
  341. {
  342. //处理相册备份
  343. [[backupsFileManager shareInstance] checkReBackupsFileFun];
  344. [[uploadFileManager shareInstance] checkReUploadFileFun];
  345. [[downloadManager shareInstance] checkReDownloadFileFun];
  346. [self checkCommandSendTaskFun];
  347. }
  348. -(void)addCommandSendTaskFunWithType:(NSString*)type WithCommandStr:(NSString*)commandStr
  349. {
  350. if(!commandSendCheckArr){
  351. commandSendCheckArr = [NSMutableArray new];
  352. }
  353. BOOL didAddType = NO;
  354. for (commandSendCheckModel *model in commandSendCheckArr) {
  355. if([model.type isEqualToString:type]){
  356. didAddType = YES;
  357. model.reSendNum = 0;
  358. model.sendTimerStamp = [iTools getNowTimeStamp];
  359. break;
  360. }
  361. }
  362. if(!didAddType){
  363. commandSendCheckModel *model = [commandSendCheckModel new];
  364. model.commandStr = commandStr;
  365. model.type = type;
  366. model.reSendNum = 0;
  367. model.sendTimerStamp = [iTools getNowTimeStamp];
  368. [commandSendCheckArr addObject:model];
  369. }
  370. }
  371. -(void)checkCommandSendTaskFun
  372. {
  373. if(commandSendCheckArr && commandSendCheckArr.count >0){
  374. for (commandSendCheckModel *model in commandSendCheckArr) {
  375. if(model.reSendNum < 3){
  376. model.reSendNum ++;
  377. if(model.commandStr){
  378. [self send_data:model.commandStr];
  379. HLog(@"\n\n\n任务重发 重发次数:%ld 指令:%@\n\n\n",model.reSendNum,model.commandStr);
  380. }
  381. // if([model.type isEqualToString:@"offline_notification"]){
  382. // model.reSendNum = 1;//只要不收到
  383. // }
  384. }
  385. }
  386. }
  387. }
  388. -(void)deleteCommandSendTaskFunWith:(NSString*)type
  389. {
  390. if(commandSendCheckArr && commandSendCheckArr.count >0){
  391. NSArray *taskArr = [NSArray arrayWithArray:commandSendCheckArr];
  392. for (commandSendCheckModel *model in taskArr) {
  393. if([type isEqualToString:model.type]){
  394. [commandSendCheckArr removeObject:model];
  395. }
  396. }
  397. }
  398. }
  399. - (void)getExtraFilesResponseFun:(NSDictionary *)dataDict
  400. {
  401. cloudPhoneExtraFileListModel *model = [[cloudPhoneExtraFileListModel alloc] initWithDictionary:dataDict error:nil];
  402. ksharedAppDelegate.cloudPhoneExtraFileListMod = model;
  403. }
  404. - (void)saveLastImageFun
  405. {
  406. UIImage *image = [UIImage imageWithCIImage:saveCIImage];
  407. if(image){ //执行返回最后一帧
  408. //[mPlayerView.showImageView setImage:image];
  409. NSString *filePath = kSHPath_cloudPhone_last_image;
  410. NSString *folderPath = [kSHPath_cloudPhone_last_image stringByDeletingLastPathComponent];
  411. [[NSFileManager defaultManager] removeItemAtPath:folderPath error:nil];
  412. [cachesFileManager getCreateFilePath:folderPath];
  413. NSData*imageData = UIImagePNGRepresentation(image);
  414. BOOL ret = [imageData writeToFile:filePath atomically:NO];
  415. if (ret) {
  416. }
  417. }
  418. }
  419. - (void)readLastImageFun
  420. {
  421. NSString *filePath = kSHPath_cloudPhone_last_image;
  422. UIImage *image = [UIImage imageWithContentsOfFile:filePath];
  423. if(image && !saveCIImage){
  424. [mPlayerView.showImageView setImage:image];
  425. }
  426. }
  427. - (void)getExtraMediaEventResponseFun:(NSDictionary *)dataDict
  428. {
  429. extraMediaEventModel *model = [[extraMediaEventModel alloc] initWithDictionary:dataDict error:nil];
  430. NSString *tip = nil;
  431. if(model.data.event == 0){
  432. tip = NSLocalizedString(@"disk_insertion_tip",nil);
  433. [self showInsertPopViewFun:model.data.name];
  434. }
  435. else if(model.data.event == 1){
  436. tip = NSLocalizedString(@"disk_extract_tip",nil);
  437. }
  438. else if(model.data.event == 2){
  439. tip = NSLocalizedString(@"disk_save_extract_tip",nil);
  440. }
  441. NSString *totalTips = [[NSString alloc] initWithFormat:@"%@%@",model.data.name,tip];
  442. mainBlock(^{
  443. [[iToast makeText:totalTips] show];
  444. });
  445. }
  446. #pragma mark 显示插入UI弹框
  447. - (void)showInsertPopViewFun:(NSString*)name
  448. {
  449. if(self->curUSBInsertPopV){
  450. [self->curUSBInsertPopV removeFromSuperview];
  451. self->curUSBInsertPopV = nil;
  452. }
  453. self->curUSBInsertPopV = [[USBInsertPopView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H) withName:name];
  454. UIViewController*lastVC = self.navigationController.viewControllers.lastObject;
  455. //[[iTools getKeyWindow] addSubview:self->curUSBInsertPopV];
  456. [lastVC.view addSubview:self->curUSBInsertPopV];
  457. }
  458. @end