PlayerViewController+otherDelegate.mm 14 KB

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