PlayerViewController+otherDelegate.mm 17 KB

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