PlayerViewController+otherDelegate.mm 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  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. @implementation PlayerViewController (otherDelegate)
  18. #pragma mark ComontAlretViewControllerDelegate
  19. - (void)CommonAlertokBtnClickPressed{
  20. //HLog("11111");
  21. if(self->logoutAlertVC){
  22. self->logoutAlertVC = nil;
  23. }
  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. NSString *newVersion = model.data.data.MyNewVersion;
  127. if (!hostImgVer || hostImgVer.length < 3) {
  128. return;
  129. }
  130. if (!newVersion || newVersion.length < 3) {
  131. return;
  132. }
  133. NSArray *hostImgVerArr = [hostImgVer componentsSeparatedByString:@"."];
  134. NSArray *newVersionArr = [newVersion componentsSeparatedByString:@"."];
  135. if(!hostImgVerArr || !newVersionArr){
  136. return;
  137. }
  138. NSInteger curMaxCount = hostImgVerArr.count > newVersionArr.count ? newVersionArr.count : hostImgVerArr.count;
  139. BOOL isNeedShow = NO;
  140. for(int i=0;i<curMaxCount;i++){
  141. NSString * verNum = newVersionArr[i];
  142. NSString * hostNum = hostImgVerArr[i];
  143. if(verNum.integerValue > hostNum.integerValue){
  144. isNeedShow = YES;
  145. break;
  146. }
  147. }
  148. if(isNeedShow){
  149. [self showImageViewRenewTipViewFun];
  150. }
  151. }
  152. - (void)getCouldPhoneTvStatusResponseFun:(NSDictionary *)dataDict
  153. {
  154. TvStatusModel *model = [[TvStatusModel alloc] initWithDictionary:dataDict error:nil];
  155. [[NSNotificationCenter defaultCenter] postNotificationName:getCouldPhoneTvStatusNotification object:model];
  156. if(![model.msg containsString:@"PushStreamBActivity"])
  157. {
  158. return;
  159. }
  160. UIViewController*topVc = self.navigationController.viewControllers.lastObject;
  161. if([topVc isKindOfClass:[PlayerViewController class]]){
  162. [[iToast makeText:NSLocalizedString(@"tv_p2p_ing",nil)] show];
  163. }
  164. }
  165. - (void)showImageViewRenewTipViewFun
  166. {
  167. imageVersionRenewTipView * RenewTipView = [[imageVersionRenewTipView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H)];
  168. [self.view addSubview:RenewTipView];
  169. [self.view bringSubviewToFront:RenewTipView];
  170. }
  171. #pragma mark 监听文件开始的的通知
  172. - (void)beginGotoUploadFileFun:(NSNotification *)notification
  173. {
  174. self.isSuspendUploadType = NO;
  175. uploadFileDataModel *uploadFileDataMod = [notification object];
  176. //HLog(@"%@",uploadFileDataMod);
  177. // if(self.curUploadFileDataMod && uploadFileDataMod.bg_id.integerValue == self.curUploadFileDataMod.bg_id.integerValue){
  178. // return;
  179. // }
  180. self.curUploadFileDataMod = uploadFileDataMod;
  181. if(![uploadFileDataMod isKindOfClass:[uploadFileDataMod class]]){
  182. HLog(@"上传的文件类型不对");
  183. return;
  184. }
  185. [self ApplyUploadFileFun];
  186. }
  187. - (void)applyUploadFileServiceResponseFun:(NSDictionary *)dataDict
  188. {
  189. if([dataDict isKindOfClass:[NSDictionary class]]){
  190. if ([[dataDict allKeys] containsObject:@"data"]) {
  191. NSDictionary *data = dataDict[@"data"];
  192. if ([[data allKeys] containsObject:@"status"]) {
  193. NSString *status = [data objectForKey:@"status"];
  194. if(![status isKindOfClass:[NSString class]]){
  195. status = [[NSString alloc] initWithFormat:@"%@",status];
  196. }
  197. //if(1)
  198. if([status isEqualToString:@"1"])
  199. {
  200. //[self tryAgainApplyUploadFun];
  201. [self clearUploadFileDataFun];
  202. [[uploadFileManager shareInstance] uploadFileFailFun];
  203. }else if ([status isEqualToString:@"0"]){
  204. if ([[data allKeys] containsObject:@"taskUid"]) {
  205. NSString *taskUid = data[@"taskUid"];
  206. if(![status isKindOfClass:[NSString class]]){
  207. taskUid = [[NSString alloc] initWithFormat:@"%@",taskUid];
  208. }
  209. if(taskUid && [taskUid isEqualToString:self.taskUid]){
  210. NSNumber * fileLengthNum = @0;
  211. if ([[data allKeys] containsObject:@"fileLength"])
  212. {
  213. fileLengthNum = data[@"fileLength"];
  214. }
  215. // [[uploadFileManager shareInstance] changeUploadFileState:uploadStateUploading withDidUploadBytes:[fileLengthNum integerValue] withModel:self.curUploadFileDataMod complete:^(BOOL isSuccess) {
  216. //
  217. // }];
  218. if([fileLengthNum integerValue] == self.curUploadFileDataMod.totalBytes){
  219. self.taskUid = nil;
  220. NSMutableArray *delArr = [NSMutableArray new];
  221. [delArr addObject:self.curUploadFileDataMod];
  222. [[uploadFileManager shareInstance] deleteUploadFileRecordBy:delArr withDelCache:NO complete:^(BOOL isSuccess) {
  223. if (isSuccess) {
  224. [[NSNotificationCenter defaultCenter] postNotificationName:uploadFileDeteleNotification object:self.curUploadFileDataMod];
  225. }
  226. }];
  227. mainBlock(^{
  228. [[iToast makeText:NSLocalizedString(@"File_upload_file_already_exists",nil)] show];
  229. });
  230. HLog(@"hxd already 上传任务异常终止")
  231. return;
  232. }
  233. if(self.curUploadFileDataMod.curUploadFileType == uploadFileTypeImage){
  234. [self beginGotoUploadImageFun:fileLengthNum];
  235. }
  236. else{
  237. [self beginGotoUploadVidelFun:fileLengthNum];
  238. }
  239. }
  240. }
  241. }
  242. }
  243. }
  244. else{
  245. //异常
  246. [self tryAgainApplyUploadFun];
  247. }
  248. }
  249. else{
  250. //异常
  251. [self tryAgainApplyUploadFun];
  252. }
  253. }
  254. #pragma mark 图片上传
  255. -(void)beginGotoUploadImageFun:(NSNumber*)fileLengthNum{
  256. self.cutFileDataArr = [self fileCutPartsBy:self.AllFileData withDidUpLoadSize:[fileLengthNum integerValue]];
  257. if(!self.cutFileDataArr){
  258. [self clearUploadFileDataFun];
  259. [[uploadFileManager shareInstance] uploadFileFailFun];
  260. self.taskUid = nil;
  261. mainBlock(^{
  262. [[iToast makeText:NSLocalizedString(@"File_upload_fail",nil)] show];
  263. });
  264. HLog(@"hxd fail 上传任务异常终止")
  265. return;
  266. }
  267. //答复的taskUid 跟申请的一致 开发发送内容
  268. [self upLoadFileFun];
  269. }
  270. #pragma mark 视频上传
  271. //每次从文件重新切一片 传一片
  272. -(void)beginGotoUploadVidelFun:(NSNumber*)fileLengthNum{
  273. NSData *data = [self cutVideoFileFunAtIndex:fileLengthNum.longLongValue];
  274. HLog(@"data leng:%ld",[data length]);
  275. self.AllFileData = data;
  276. self.cutFileDataArr = [self fileCutPartsBy:self.AllFileData withDidUpLoadSize:0];
  277. self.indexOfUploadFlie = 0;
  278. HLog(@"data leng:%ld",[data length]);
  279. //return;
  280. // NSString*videoPathStr = [cachesFileManager getFilePathWithName:self.curUploadFileDataMod.filename type:uploadFileTypeVideo];
  281. // self.AllFileData = [NSData dataWithContentsOfFile:videoPathStr];
  282. // self.cutFileDataArr = [self fileCutPartsBy:self.AllFileData withDidUpLoadSize:[fileLengthNum integerValue]];
  283. if(!self.cutFileDataArr){
  284. [self clearUploadFileDataFun];
  285. [[uploadFileManager shareInstance] uploadFileFailFun];
  286. self.taskUid = nil;
  287. mainBlock(^{
  288. [[iToast makeText:NSLocalizedString(@"File_upload_fail",nil)] show];
  289. });
  290. HLog(@"hxd fail 上传任务异常终止")
  291. return;
  292. }
  293. //答复的taskUid 跟申请的一致 开发发送内容
  294. [self upLoadFileFun];
  295. }
  296. #pragma mark 分段读视频文件
  297. -(NSData*)cutVideoFileFunAtIndex:(NSUInteger)dataIndex{
  298. NSString *filePath = [cachesFileManager getFilePathWithName:self.curUploadFileDataMod.filename type:uploadFileTypeVideo]; // 文件路径
  299. NSFileManager *manager0 = [NSFileManager defaultManager];
  300. if(![manager0 fileExistsAtPath:filePath]) {
  301. return [NSData new];
  302. }
  303. NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingAtPath:filePath]; // 创建文件句柄
  304. // 设置分段读取的大小,这里以每次读取1KB为例
  305. //const NSUInteger chunkSize = 50 * 1024 *1024;
  306. const NSUInteger chunkSize = 5 * 1024 *1024;
  307. NSMutableData *data = [NSMutableData data];
  308. if (fileHandle) {
  309. long long endOfFile = [fileHandle seekToEndOfFile];
  310. if (endOfFile >= chunkSize) {
  311. // 读取文件的分段数据到某个位置
  312. [fileHandle seekToFileOffset:dataIndex];
  313. // 读取文件的分段数据
  314. NSData* chunk = [fileHandle readDataOfLength:chunkSize];
  315. if (chunk) {
  316. [data appendData:chunk];
  317. }
  318. }
  319. else{
  320. // 读取文件的分段数据到某个位置
  321. [fileHandle seekToFileOffset:dataIndex];
  322. [data appendData:[fileHandle readDataToEndOfFile]];
  323. }
  324. // 在这里可以对文件内容进行处理
  325. // ...
  326. // 关闭文件句柄
  327. [fileHandle closeFile];
  328. }
  329. return data;
  330. }
  331. - (void)upLoadFileFunServiceResponseFun:(NSDictionary *)dataDict
  332. {
  333. //{"type":"uploadFileRandomRet","data":{"progress":"9\/10","filePath":"/sdcard/Download/IMG_0036.JPG","status":"0","msg":"success"}}
  334. if([dataDict isKindOfClass:[NSDictionary class]]){
  335. if ([[dataDict allKeys] containsObject:@"data"]) {
  336. NSDictionary *data = dataDict[@"data"];
  337. if ([[data allKeys] containsObject:@"status"]) {
  338. NSString *status = [data objectForKey:@"status"];
  339. if(![status isKindOfClass:[NSString class]]){
  340. status = [[NSString alloc] initWithFormat:@"%@",status];
  341. }
  342. if ([status isEqualToString:@"1"]) {
  343. //[self tryAgainApplyUploadFun];
  344. [self clearUploadFileDataFun];
  345. [[uploadFileManager shareInstance] uploadFileFailFun];
  346. }else if ([status isEqualToString:@"0"]){
  347. NSNumber * fileLengthNum = @0;
  348. if ([[data allKeys] containsObject:@"fileLenth"])
  349. {
  350. fileLengthNum = data[@"fileLenth"];
  351. }
  352. [self handleUploadingFun:fileLengthNum];
  353. }
  354. }
  355. }
  356. else{
  357. //异常
  358. [self tryAgainApplyUploadFun];
  359. }
  360. }
  361. else{
  362. //异常
  363. [self tryAgainApplyUploadFun];
  364. }
  365. }
  366. #pragma mark 申请上传文件
  367. - (void)ApplyUploadFileFun
  368. {
  369. //if(!self.taskUid){
  370. self.taskUid = [iTools getTaskUidStr];
  371. self.fileName = self.curUploadFileDataMod.filename;
  372. if(self.curUploadFileDataMod.curUploadFileType == uploadFileTypeVideo){
  373. //self.AllFileData = self.curUploadFileDataMod.videoData;
  374. }
  375. else{
  376. self.AllFileData = self.curUploadFileDataMod.imageData;
  377. }
  378. self.indexOfUploadFlie = 0;
  379. //HLog(@"%@ %@",self.taskUid,self.fileName);
  380. //self.cutFileDataArr = [self fileCutPartsBy:self.AllFileData];
  381. //}
  382. NSString * commandStr = [RCCommandHelp applyForUploadFileBy:self.taskUid filePath:self.fileName];
  383. [self.commandChannelManager rc_sendData:commandStr];
  384. }
  385. #pragma mark 遇到异常时 重新上传
  386. - (void)tryAgainApplyUploadFun
  387. {
  388. self.taskUid = nil;
  389. [self ApplyUploadFileFun];
  390. }
  391. #pragma mark 处理上传过程
  392. - (void)handleUploadingFun:(NSNumber*)fileLengthNum
  393. {
  394. if(self.isSuspendUploadType){
  395. //暂停
  396. self.taskUid = nil;
  397. //NSInteger didUploadSize = (self.indexOfUploadFlie+1) * (self.cutFileEachPieceSzie);
  398. NSInteger didUploadSize = fileLengthNum.longLongValue;
  399. [[uploadFileManager shareInstance] changeUploadFileState:uploadStateSuspend withDidUploadBytes:didUploadSize withModel:self.curUploadFileDataMod complete:^(BOOL isSuccess) {
  400. }];
  401. return;
  402. }
  403. if(self.indexOfUploadFlie < self.cutFileDataArr.count -1) {
  404. //NSInteger didUploadSize = (self.indexOfUploadFlie+1) * (self.cutFileEachPieceSzie);
  405. NSInteger didUploadSize = fileLengthNum.longLongValue;
  406. [[uploadFileManager shareInstance] changeUploadFileState:uploadStateUploading withDidUploadBytes:didUploadSize withModel:self.curUploadFileDataMod complete:^(BOOL isSuccess) {
  407. }];
  408. self.indexOfUploadFlie ++;
  409. [self upLoadFileFun];
  410. }
  411. else if(self.curUploadFileDataMod.curUploadFileType == uploadFileTypeVideo && fileLengthNum && fileLengthNum.longLongValue < self.curUploadFileDataMod.totalBytes){
  412. //视频做了二次切割 不一定上传完了
  413. HLog(@"视频上传传完一片 再来一片");
  414. [self beginGotoUploadVidelFun:fileLengthNum];
  415. }
  416. else{
  417. HLog(@"上传完成");
  418. [self clearUploadFileDataFun];
  419. [[uploadFileManager shareInstance] uploadFileDoneFun];
  420. }
  421. }
  422. -(void)clearUploadFileDataFun{
  423. //上传数据清空
  424. self.taskUid = nil;
  425. self.fileName = nil;
  426. self.AllFileData = nil;
  427. self.indexOfUploadFlie = 0;
  428. self.cutFileDataArr = nil;
  429. self.curUploadFileDataMod = nil;
  430. self.isSuspendUploadType = NO;
  431. }
  432. - (Byte)getBCC:(NSData *)data {
  433. Byte bcc = 0;
  434. unsigned char *bytes = (unsigned char *)[data bytes];
  435. for (int i = 0; i < [data length]; i++) {
  436. bcc = (Byte)(bcc ^ bytes[i]);
  437. }
  438. return bcc;
  439. }
  440. #pragma mark 文件切片
  441. -(NSMutableArray *)fileCutPartsBy:(NSData*)curData withDidUpLoadSize:(NSInteger)didLoadSize{
  442. NSData * data = curData;
  443. NSUInteger allLength = data.length;
  444. NSUInteger subs = 1*1024*1024;//4096;//要切片的大小,我这里设置的是4096字节
  445. //NSUInteger subs = 31*1024;//4096;//要切片的大小,内存没有暴增
  446. self.cutFileEachPieceSzie = subs;
  447. NSInteger index = 0;//起始位置
  448. if(didLoadSize != 0){
  449. if (didLoadSize % subs != 0){
  450. //出错了
  451. return nil;
  452. }
  453. else{
  454. // index = didLoadSize/subs;
  455. // allLength = allLength - didLoadSize;
  456. self.indexOfUploadFlie = didLoadSize/subs;
  457. }
  458. }
  459. NSMutableArray *dataArray =[NSMutableArray new];
  460. do {
  461. //@autoreleasepool {
  462. if (allLength>subs) {
  463. NSRange range =NSMakeRange(index*subs, subs);
  464. index++;
  465. //NSLog(@"%@",NSStringFromRange(range));
  466. [dataArray addObject:[data subdataWithRange:range]];
  467. allLength = allLength - subs;
  468. }else{
  469. NSRange range = NSMakeRange(index*subs, allLength);
  470. //NSLog(@"%@",NSStringFromRange(range));
  471. [dataArray addObject:[data subdataWithRange:range]];
  472. allLength = 0;
  473. }
  474. //}
  475. } while (allLength>0);
  476. HLog(@"dataArray leng:%ld",dataArray.count);//最后得到切片的结果,数组里面是NSData对象
  477. return dataArray;
  478. }
  479. // int转NSData
  480. - (NSData *)int2Data:(int)i{
  481. Byte b0 = i & 0xff;
  482. Byte b1 = i >> 8 & 0xff;
  483. Byte b2 = i >> 16 & 0xff;
  484. Byte b3 = i >> 24 & 0xff;
  485. // 有大小端模式问题?
  486. //Byte result[] = {b0, b1, b2, b3};
  487. Byte result[] = {b3, b2, b1, b0};
  488. return [NSData dataWithBytes:result length:sizeof(result)];
  489. }
  490. // short转NSData
  491. - (NSData *)short2Data:(short)i{
  492. Byte b0 = i & 0xff;
  493. Byte b1 = i >> 8 & 0xff;
  494. // 有大小端模式问题?
  495. //Byte result[] = {b0, b1, b2, b3};
  496. Byte result[] = { b1, b0};
  497. return [NSData dataWithBytes:result length:sizeof(result)];
  498. }
  499. #pragma mark 可以发送文件了
  500. /*
  501. 文件数据字节流byte[]
  502. 格式1:下载日志文件压缩包
  503. |head|msgType|taskId| datalen | curNum | totalNum| data |bcc校验|end|
  504. 长度: 1 1 6 (curNum+totalNum+data) 4 4 datalen- 8 1 1
  505. 0x68 0x0e 0x16
  506. bcc校验从第1位 也就是从msgType起 到 校验位前(不包含校验位)数据作bcc校验
  507. */
  508. - (void)upLoadFileFun
  509. {
  510. //HLog(@"上传文件%ld/%ld",self.indexOfUploadFlie +1,self.cutFileDataArr.count);
  511. if(self.cutFileDataArr.count <= self.indexOfUploadFlie)
  512. {
  513. return;
  514. }
  515. //data
  516. NSData *curData = self.cutFileDataArr[self.indexOfUploadFlie];
  517. //HLog(@"headData:%@",curData);
  518. //head
  519. unsigned char headNum = 104;
  520. NSData *headData = [NSMutableData dataWithBytes:&headNum length:sizeof(headNum)];
  521. //HLog(@"headData:%@",headData);
  522. //msgType
  523. //unsigned char msgType = 12;
  524. unsigned char msgType = 15;
  525. NSData *msgTypeData = [NSMutableData dataWithBytes:&msgType length:sizeof(msgType)];
  526. //HLog(@"msgTypeData:%@",msgTypeData);
  527. //taskId
  528. NSData *taskIdData = [self.taskUid dataUsingEncoding:NSUTF8StringEncoding];
  529. //HLog(@"taskIdData:%@",taskIdData);
  530. //datalen
  531. int datalenNum = int([curData length] +(4+4));
  532. //NSData *datalenData = [NSData dataWithBytes:&datalenNum length:sizeof(datalenNum)];
  533. NSData *datalenData = [self int2Data:datalenNum];
  534. //HLog(@"datalenData %@",datalenData);
  535. //curNum
  536. int curNum = (int)self.indexOfUploadFlie;
  537. //NSData *curNumData = [NSData dataWithBytes:&curNum length:sizeof(curNum)];
  538. NSData * curNumData = [self int2Data:curNum];
  539. //HLog(@"curNumData:%@",curNumData);
  540. //totalNum
  541. int totalNum = (int)self.cutFileDataArr.count;
  542. //NSData *totalNumData = [NSData dataWithBytes:&totalNum length:sizeof(totalNum)];
  543. NSData * totalNumData = [self int2Data:totalNum];
  544. //HLog(@"totalNumData:%@",totalNumData);
  545. NSMutableData *checkBCCData = [NSMutableData new];
  546. [checkBCCData appendData:msgTypeData];
  547. [checkBCCData appendData:taskIdData];
  548. [checkBCCData appendData:datalenData];
  549. [checkBCCData appendData:curNumData];
  550. [checkBCCData appendData:totalNumData];
  551. [checkBCCData appendData:curData];
  552. long length = [curData length];
  553. //HLog(@"curData length %d",length);
  554. Byte bccCheck = [self getBCC:checkBCCData];
  555. //HLog(@"bcc 000 %d",bccCheck);
  556. //bcc校验
  557. char bccNum = (char)bccCheck;
  558. NSData *bccData = [NSMutableData dataWithBytes:&bccNum length:sizeof(bccNum)];
  559. //HLog(@"%@",bccData);
  560. //end
  561. unsigned char endNum = 22;
  562. NSData *endData = [NSMutableData dataWithBytes:&endNum length:sizeof(endNum)];
  563. //HLog(@"%@",endData);
  564. NSMutableData *sendData = [NSMutableData new];
  565. [sendData appendData:headData];
  566. [sendData appendData:checkBCCData];
  567. [sendData appendData:bccData];
  568. [sendData appendData:endData];
  569. //HLog(@"sendData length %ld",[sendData length]);
  570. [self.commandChannelManager rc_sendData:sendData];
  571. //HLog(@"文件上传sendData %@",sendData);
  572. }
  573. - (void)suspendUploadFileFun:(NSNotification *)notification
  574. {
  575. self.isSuspendUploadType = YES;
  576. }
  577. - (void)saveLastImageFun
  578. {
  579. UIImage *image = [UIImage imageWithCIImage:saveCIImage];
  580. if(image){ //执行返回最后一帧
  581. //[mPlayerView.showImageView setImage:image];
  582. NSString *filePath = kSHPath_cloudPhone_last_image;
  583. NSString *folderPath = [kSHPath_cloudPhone_last_image stringByDeletingLastPathComponent];
  584. [[NSFileManager defaultManager] removeItemAtPath:folderPath error:nil];
  585. [cachesFileManager getCreateFilePath:folderPath];
  586. NSData*imageData = UIImagePNGRepresentation(image);
  587. BOOL ret = [imageData writeToFile:filePath atomically:NO];
  588. if (ret) {
  589. }
  590. }
  591. }
  592. - (void)readLastImageFun
  593. {
  594. NSString *filePath = kSHPath_cloudPhone_last_image;
  595. UIImage *image = [UIImage imageWithContentsOfFile:filePath];
  596. if(image && !saveCIImage){
  597. [mPlayerView.showImageView setImage:image];
  598. }
  599. }
  600. @end