PlayerViewController+otherDelegate.mm 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  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. // NSString *hostImgVer = @"1.2.3";
  139. // NSString *MyNewVersion = @"1.3.0";
  140. //判断当前版本号 待更新版本
  141. if (!hostImgVer || hostImgVer.length < 3
  142. ||!MyNewVersion || MyNewVersion.length < 3) {
  143. //[self showImageViewRenewTipViewFun];
  144. return;
  145. }
  146. NSArray *versionArr = [hostImgVer componentsSeparatedByString:@"."];
  147. NSArray *MyNewVersionArr = [MyNewVersion componentsSeparatedByString:@"."];
  148. NSInteger versionArrCount = versionArr.count;
  149. NSInteger MyNewVersionArrCount = MyNewVersionArr.count;
  150. NSInteger maxCount = versionArrCount < MyNewVersionArrCount ? versionArrCount:MyNewVersionArrCount;
  151. BOOL isNeedShowType = NO;
  152. //判断是否要更新镜像框
  153. if(maxCount > 0){
  154. for (int i=0; i<maxCount; i++) {
  155. NSString * numberStr1 = versionArr[i];
  156. NSString * numberStr2 = MyNewVersionArr[i];
  157. if(numberStr2.intValue > numberStr1.intValue){
  158. isNeedShowType =YES;
  159. break;
  160. }
  161. }
  162. }
  163. if(isNeedShowType){
  164. [self showImageViewRenewTipViewFun];
  165. }
  166. //是否禁用文件传输 (1.3以及以上的镜像可以使用文件传输)
  167. if(versionArr.count >= 2)
  168. {
  169. NSString * oneStr = versionArr[0];
  170. NSString * twoStr = versionArr[1];
  171. if(oneStr.integerValue <=1 && twoStr.integerValue <=2){//禁用
  172. ksharedAppDelegate.DisabledFileTransferType = YES;
  173. }
  174. else{
  175. ksharedAppDelegate.DisabledFileTransferType = NO;
  176. }
  177. }
  178. }
  179. - (void)getCouldPhoneTvStatusResponseFun:(NSDictionary *)dataDict
  180. {
  181. TvStatusModel *model = [[TvStatusModel alloc] initWithDictionary:dataDict error:nil];
  182. [[NSNotificationCenter defaultCenter] postNotificationName:getCouldPhoneTvStatusNotification object:model];
  183. if(![model.msg containsString:@"PushStreamBActivity"])
  184. {
  185. return;
  186. }
  187. UIViewController*topVc = self.navigationController.viewControllers.lastObject;
  188. if([topVc isKindOfClass:[PlayerViewController class]]){
  189. [[iToast makeText:NSLocalizedString(@"tv_p2p_ing",nil)] show];
  190. }
  191. }
  192. - (void)showImageViewRenewTipViewFun
  193. {
  194. imageVersionRenewTipView * RenewTipView = [[imageVersionRenewTipView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H)];
  195. [self.view addSubview:RenewTipView];
  196. [self.view bringSubviewToFront:RenewTipView];
  197. }
  198. - (void)createFolderBeginNotFun:(NSNotification *)notification
  199. {
  200. NSString *folderName = [notification object];
  201. if(folderName && folderName.length >0){
  202. NSString * commandStr = [RCCommandHelp applyForCreateFolderwithFolderName:folderName];
  203. [self.commandChannelManager rc_sendData:commandStr];
  204. }
  205. }
  206. - (void)createFolderResponseFun:(NSDictionary *)dataDict
  207. {
  208. couldPhoneCommonModel *model = [[couldPhoneCommonModel alloc] initWithDictionary:dataDict error:nil];
  209. if(model){
  210. NSNumber *curNum = [NSNumber numberWithInteger:model.status];
  211. [[NSNotificationCenter defaultCenter] postNotificationName:createFolderDoneNotification object:curNum];/*发送通知*/
  212. }
  213. }
  214. - (void)getFolderListBeginNotFun:(NSNotification *)notification
  215. {
  216. NSString * commandStr = [RCCommandHelp getCreateFolderList];
  217. [self.commandChannelManager rc_sendData:commandStr];
  218. }
  219. - (void)getFolderListResponseFun:(NSDictionary *)dataDict
  220. {
  221. [[NSNotificationCenter defaultCenter] postNotificationName:getFolderListDoneNotification object:dataDict];/*发送通知*/
  222. }
  223. - (void)searchFileListBeginFun:(NSNotification *)notification
  224. {
  225. NSMutableDictionary *objectDict = [notification object];
  226. NSNumber *curNum = @1;
  227. if ([[objectDict allKeys] containsObject:@"type"]) {
  228. curNum = [objectDict objectForKey:@"type"];
  229. }
  230. NSString *pathStr = @"";
  231. if ([[objectDict allKeys] containsObject:@"path"]) {
  232. pathStr = [objectDict objectForKey:@"path"];
  233. }
  234. NSString *fileType = @"video";
  235. if(curNum.boolValue)
  236. {
  237. fileType = @"jpg";
  238. }
  239. NSString * commandStr = [RCCommandHelp searchCouldPhoneFilewithType:fileType withPath:pathStr];
  240. [self.commandChannelManager rc_sendData:commandStr];
  241. }
  242. - (void)searchFileListResponseFun:(NSDictionary *)dataDict
  243. {
  244. [[NSNotificationCenter defaultCenter] postNotificationName:searchFileListDoneNotification object:dataDict];/*发送通知*/
  245. }
  246. // NSData转int
  247. - (int)data2Int:(NSData *)data{
  248. Byte *byte = (Byte *)[data bytes];
  249. // 有大小端模式问题?
  250. return (byte[0] << 24) + (byte[1] << 16) + (byte[2] << 8) + (byte[3]);
  251. }
  252. - (void)handleDownloadResponseFunBy:(id)message
  253. {
  254. NSData *curData = (NSData *)message;
  255. // if(curData.length < 20){
  256. // return;
  257. // }
  258. //head
  259. NSData *headData = [curData subdataWithRange:NSMakeRange(0, 1)];
  260. char head = 0;//104;
  261. [headData getBytes:&head length:sizeof(head)];
  262. //HLog(@"head: %d",head);
  263. //msgType 0x11(17)
  264. NSData *msgTypeData = [curData subdataWithRange:NSMakeRange(1, 1)];
  265. char msgType = 0;
  266. [msgTypeData getBytes:&msgType length:sizeof(msgType)];
  267. //HLog(@"msgType: %d",msgType);
  268. //taskId 6位字符串
  269. NSData *taskIdData = [curData subdataWithRange:NSMakeRange(2, 6)];
  270. NSString* taskIdStr = [[NSString alloc] initWithData:taskIdData encoding:NSUTF8StringEncoding];;
  271. HLog(@"taskId: %@",taskIdStr);
  272. if(curData.length <= 15){
  273. HLog(@"消息长度不对不处理");
  274. return;
  275. }
  276. //datalen
  277. NSData *datalenData = [curData subdataWithRange:NSMakeRange(8, 4)];
  278. int datalen = [self data2Int:datalenData];
  279. //HLog(@"datalen: %d",datalen);
  280. //curNum
  281. NSData *curNumData = [curData subdataWithRange:NSMakeRange(12, 4)];
  282. int curNum = [self data2Int:curNumData];;
  283. //HLog(@"curNum: %d",curNum);
  284. //totalNum
  285. NSData *totalNumData = [curData subdataWithRange:NSMakeRange(16, 4)];
  286. int totalNum = [self data2Int:totalNumData];
  287. //HLog(@"totalNum: %d",totalNum);
  288. BOOL isDownloadDone = curNum == totalNum ? YES : NO;
  289. HLog(@"taskUid:%@ curNum:%d totalNum: %d datalen:%d isDownloadDone:%d",taskIdStr,curNum,totalNum,datalen -8,isDownloadDone);
  290. if(curData.length <= 23){
  291. //data 的位置 装 成功或者失败
  292. NSData *failTypeData = [curData subdataWithRange:NSMakeRange(20, 1)];
  293. //0xcc (204)失败 0xcd (205)文件不存在 0xdd (221)完成 0xbb 187 完成
  294. __block Byte failType;
  295. [failTypeData getBytes:&failType length:sizeof(failType)];
  296. if(taskIdStr && [taskIdStr isEqualToString:self.downloadFileTaskUid]){
  297. if(failType == 0xcc || failType == 0xcf){
  298. [[downloadManager shareInstance] DownloadFileFailOneFileFun];
  299. }
  300. else if(failType == 0xcd ){
  301. [[downloadManager shareInstance] suspendDownloadFileFun:YES];
  302. NSString *tipStr = NSLocalizedString(@"disk_not_find_tip",nil);
  303. mainBlock(^{
  304. [[iToast makeText:tipStr] show];
  305. });
  306. }
  307. else if(failType == 0xdd || failType == 0xbb){
  308. [self downloadFileFunServiceResponseFun:[NSData new] with:YES];
  309. }
  310. else{
  311. HLog(@"下载数据未知错误");
  312. [[downloadManager shareInstance] DownloadFileFailOneFileFun];
  313. }
  314. }
  315. return;
  316. }
  317. if(curData.length <= (20 + datalen - 8)){
  318. HLog(@"下载数据解析出错了");
  319. return;
  320. }
  321. NSData *fileData = [curData subdataWithRange:NSMakeRange(20, datalen-8)];
  322. if([taskIdStr isEqualToString:self.downloadFileTaskUid]){
  323. [self downloadFileFunServiceResponseFun:fileData with:NO];
  324. }
  325. }
  326. - (void)checkAllTaskFun
  327. {
  328. //处理相册备份
  329. [[backupsFileManager shareInstance] checkReBackupsFileFun];
  330. [[uploadFileManager shareInstance] checkReUploadFileFun];
  331. [[downloadManager shareInstance] checkReDownloadFileFun];
  332. [self checkCommandSendTaskFun];
  333. }
  334. -(void)addCommandSendTaskFunWithType:(NSString*)type WithCommandStr:(NSString*)commandStr
  335. {
  336. if(!commandSendCheckArr){
  337. commandSendCheckArr = [NSMutableArray new];
  338. }
  339. BOOL didAddType = NO;
  340. for (commandSendCheckModel *model in commandSendCheckArr) {
  341. if([model.type isEqualToString:type]){
  342. didAddType = YES;
  343. model.reSendNum = 0;
  344. model.sendTimerStamp = [iTools getNowTimeStamp];
  345. break;
  346. }
  347. }
  348. if(!didAddType){
  349. commandSendCheckModel *model = [commandSendCheckModel new];
  350. model.commandStr = commandStr;
  351. model.type = type;
  352. model.reSendNum = 0;
  353. model.sendTimerStamp = [iTools getNowTimeStamp];
  354. [commandSendCheckArr addObject:model];
  355. }
  356. }
  357. -(void)checkCommandSendTaskFun
  358. {
  359. if(commandSendCheckArr && commandSendCheckArr.count >0){
  360. for (commandSendCheckModel *model in commandSendCheckArr) {
  361. if(model.reSendNum < 3){
  362. model.reSendNum ++;
  363. if(model.commandStr){
  364. [self send_data:model.commandStr];
  365. HLog(@"\n\n\n任务重发 重发次数:%ld 指令:%@\n\n\n",model.reSendNum,model.commandStr);
  366. }
  367. // if([model.type isEqualToString:@"offline_notification"]){
  368. // model.reSendNum = 1;//只要不收到
  369. // }
  370. }
  371. }
  372. }
  373. }
  374. -(void)deleteCommandSendTaskFunWith:(NSString*)type
  375. {
  376. if(commandSendCheckArr && commandSendCheckArr.count >0){
  377. NSArray *taskArr = [NSArray arrayWithArray:commandSendCheckArr];
  378. for (commandSendCheckModel *model in taskArr) {
  379. if([type isEqualToString:model.type]){
  380. [commandSendCheckArr removeObject:model];
  381. }
  382. }
  383. }
  384. }
  385. - (void)getExtraFilesResponseFun:(NSDictionary *)dataDict
  386. {
  387. cloudPhoneExtraFileListModel *model = [[cloudPhoneExtraFileListModel alloc] initWithDictionary:dataDict error:nil];
  388. ksharedAppDelegate.cloudPhoneExtraFileListMod = model;
  389. }
  390. - (void)saveLastImageFun
  391. {
  392. UIImage *image = [UIImage imageWithCIImage:saveCIImage];
  393. if(image){ //执行返回最后一帧
  394. //[mPlayerView.showImageView setImage:image];
  395. NSString *filePath = kSHPath_cloudPhone_last_image;
  396. NSString *folderPath = [kSHPath_cloudPhone_last_image stringByDeletingLastPathComponent];
  397. [[NSFileManager defaultManager] removeItemAtPath:folderPath error:nil];
  398. [cachesFileManager getCreateFilePath:folderPath];
  399. NSData*imageData = UIImagePNGRepresentation(image);
  400. BOOL ret = [imageData writeToFile:filePath atomically:NO];
  401. if (ret) {
  402. }
  403. }
  404. }
  405. - (void)readLastImageFun
  406. {
  407. NSString *filePath = kSHPath_cloudPhone_last_image;
  408. UIImage *image = [UIImage imageWithContentsOfFile:filePath];
  409. if(image && !saveCIImage){
  410. [mPlayerView.showImageView setImage:image];
  411. }
  412. }
  413. - (void)getExtraMediaEventResponseFun:(NSDictionary *)dataDict
  414. {
  415. extraMediaEventModel *model = [[extraMediaEventModel alloc] initWithDictionary:dataDict error:nil];
  416. NSString *tip = nil;
  417. if(model.data.event == 0){
  418. tip = NSLocalizedString(@"disk_insertion_tip",nil);
  419. [self showInsertPopViewFun:model.data.name];
  420. }
  421. else if(model.data.event == 1){
  422. tip = NSLocalizedString(@"disk_extract_tip",nil);
  423. }
  424. else if(model.data.event == 2){
  425. tip = NSLocalizedString(@"disk_save_extract_tip",nil);
  426. }
  427. NSString *totalTips = [[NSString alloc] initWithFormat:@"%@%@",model.data.name,tip];
  428. mainBlock(^{
  429. [[iToast makeText:totalTips] show];
  430. });
  431. }
  432. #pragma mark 显示插入UI弹框
  433. - (void)showInsertPopViewFun:(NSString*)name
  434. {
  435. if(self->curUSBInsertPopV){
  436. [self->curUSBInsertPopV removeFromSuperview];
  437. self->curUSBInsertPopV = nil;
  438. }
  439. self->curUSBInsertPopV = [[USBInsertPopView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H) withName:name];
  440. UIViewController*lastVC = self.navigationController.viewControllers.lastObject;
  441. //[[iTools getKeyWindow] addSubview:self->curUSBInsertPopV];
  442. [lastVC.view addSubview:self->curUSBInsertPopV];
  443. }
  444. @end