PlayerViewController+otherDelegate.mm 17 KB

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