PlayerViewController+otherDelegate.mm 11 KB

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