SceneDelegate.m 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228
  1. //
  2. // SceneDelegate.m
  3. // 唔即云相册
  4. //
  5. // Created by 余衡武 on 2021/12/8.
  6. //
  7. #import "SceneDelegate.h"
  8. #import "HWWebViewController.h"
  9. #import "CalculatorViewController.h"
  10. #import "SetUsePWDViewController.h"
  11. #import "GuideViewController.h"
  12. #import "BaseNavigationController.h"
  13. #import "MySetViewController.h"
  14. #import "SafeForKey.h"
  15. #import "TipsQRCodeViewController.h"
  16. #import "SetPWDFirstViewController.h"
  17. #import "ConnectTestViewController.h"
  18. //#import "PlayerViewController.h"
  19. #import "connectDeviceManager.h"
  20. #import "inputPWDViewController.h"
  21. #import "customLaunchView.h"
  22. #import "RSATool.h"
  23. #import "forgetPwdViewController.h"
  24. #import "TipsQRCodeForChangeDeviceViewController.h"
  25. #import "AFNetworkReachabilityManager.h"
  26. #import "ComontAlretViewController.h"
  27. #import "uploadFileManager.h"
  28. #import "downloadManager.h"
  29. #import "backupsFileManager.h"
  30. #import "iPhone.h"
  31. #import <WXApi.h>
  32. #import <TencentOpenAPI/QQApiInterface.h>
  33. #import <TencentOpenAPI/TencentOAuth.h>
  34. #import "NASMsgModel.h"
  35. #import "queryOneShareModel.h"
  36. #import "boxSaveFileManager.h"
  37. #import "boxDownloadFileManager.h"
  38. @interface SceneDelegate ()<SetUsePWDViewControllerDelegate,GuideViewControllerDelegate>
  39. @property(nonatomic, strong) CalculatorViewController *calculatorVC;
  40. @property(nonatomic, strong) HWWebViewController *webVC;
  41. @property(nonatomic, strong) inputPWDViewController *inputVC;
  42. @property(nonatomic, strong) customLaunchView *customLaunchV;//
  43. //@property(nonatomic, strong) PlayerViewController *curPlayerVC;
  44. @property(nonatomic, strong) BaseNavigationController *preRootPlayerNav;
  45. @property(nonatomic, assign) bool isQRCodeType;//第一次 扫码进来的
  46. //@property(nonatomic, assign) bool isNeedToShowSecretKey;//扫码进来的SN 没有密码 则需要显示秘钥
  47. @property (nonatomic, assign) BOOL isLoginAgainType;// 单点登录 点重新登录进来的
  48. @property (nonatomic, assign) BOOL isNeedToStopWork;// 无网络报错
  49. @property (nonatomic, assign) BOOL isDidShowPwdType;// 是否显示密码界面了
  50. @property(nonatomic, copy) NSString *getShareStr;//拿到分享的字符串
  51. //冷启动分享跳入用
  52. @property(nonatomic, strong) UISceneSession *session;
  53. @property(nonatomic, strong) UISceneConnectionOptions *connectionOptions;
  54. @end
  55. @implementation SceneDelegate
  56. - (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions API_AVAILABLE(ios(13.0)){
  57. if (scene) {
  58. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(guideOk:) name:GuideOkNotification object:nil];
  59. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showLockViewFun:) name:lockBypwdNotification object:nil];
  60. //[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setPwdVCFun:) name:setPwdNotification object:nil];
  61. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(forgetPwdFun:) name:forgetPwdNotification object:nil];
  62. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(forgetPwdBackFun:) name:forgetPwdBackNotification object:nil];
  63. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(forgetPwdDidSetPwdFun:) name:forgetPwdDidSetNotification object:nil];
  64. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scanChangeDeviceFun:) name:scanChangeDeviceNotification object:nil];
  65. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scanChangeDeviceBackFun:) name:scanChangeDeviceBackNotification object:nil];
  66. UIWindowScene *windowScene = (UIWindowScene *)scene;
  67. self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
  68. self.window.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
  69. // 初始化数据库
  70. [self initBrowserWindow];
  71. // 加载主页面
  72. [self enterMainVCFromScene];
  73. //
  74. [self reportVersionInfoFun];
  75. [self.window makeKeyAndVisible];
  76. ksharedAppDelegate.window = self.window;
  77. //冷启动
  78. if(connectionOptions.URLContexts != nil){
  79. _session = session;
  80. _connectionOptions = connectionOptions;
  81. // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  82. // mainBlock(^{
  83. // [self scene:scene openURLContexts:connectionOptions.URLContexts];
  84. // });
  85. // });
  86. }
  87. }
  88. }
  89. /** 进入登录界面 - 内部使用 */
  90. - (void)enterLoginVCFromScene {
  91. // UIViewController *vc = [[UIViewController alloc] init];
  92. // vc.view.backgroundColor = [UIColor redColor];
  93. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  94. // self.window.rootViewController = nvc;
  95. }
  96. /** 主界面 - 内部使用 */
  97. - (void)enterMainVCFromScene {
  98. // ConnectTestViewController *qrCodeVCNav = [[ConnectTestViewController alloc] init];
  99. // self.window.rootViewController = qrCodeVCNav;
  100. // return;/*临时测试*/
  101. if(_isNeedToStopWork){
  102. return;
  103. }
  104. /*先判断本地有无设备 无设备时需要先扫码添加设备*/
  105. NSDictionary *deviceDict = [HWDataManager getObjectWithKey:Const_Have_Add_Device];
  106. if (!deviceDict || ![[deviceDict allKeys] containsObject:Const_Have_Add_Device_SN]){
  107. /*扫码界面*/
  108. TipsQRCodeViewController *qrCodeVC = [[TipsQRCodeViewController alloc] init];
  109. BaseNavigationController *qrCodeVCNav = [[BaseNavigationController alloc] initWithRootViewController:qrCodeVC];
  110. self.window.rootViewController = qrCodeVCNav;
  111. _isQRCodeType = YES;
  112. return;
  113. }
  114. NSString *SNStr = deviceDict[@"Const_Have_Add_Device_SN"];
  115. // GuideViewController
  116. BOOL haveGuide = [HWDataManager getBoolWithKey:Const_Have_Show_Guide];
  117. if (haveGuide) {
  118. ;
  119. }else {
  120. GuideViewController *guiDeVC = [[GuideViewController alloc] init];
  121. guiDeVC.delegate = self;
  122. guiDeVC.sn = SNStr;
  123. self.window.rootViewController = guiDeVC;
  124. return;
  125. }
  126. //BOOL haveOpenMask = [HWDataManager getBoolWithKey:Const_Mask_View_Open];
  127. #ifdef developJSQ
  128. NSInteger maskModel = 1;// [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  129. #else
  130. NSInteger maskModel = [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  131. #endif
  132. //添加默认启动图片
  133. if(!_customLaunchV && maskModel == 0){
  134. _customLaunchV = [[customLaunchView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H)];
  135. [self.window addSubview:_customLaunchV];
  136. }
  137. [self getDeviceMsgInMainVCWith:deviceDict];
  138. //[self showNetErrorAlertType2Fun];
  139. }
  140. - (void)getDeviceMsgInMainVCWith:(NSDictionary*)deviceDict
  141. {
  142. KWeakSelf
  143. //有设备了先去做链接准备 // 80bec9c5
  144. NSString *SNStr = deviceDict[@"Const_Have_Add_Device_SN"];
  145. NSString *sdnId = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.sdnId;
  146. if(SNStr && !sdnId){
  147. [[connectDeviceManager shareInstance] getThridMsgBySN:SNStr needReconnect:YES didNetEnd:^(NSInteger didSuc) {
  148. if(didSuc == 0){
  149. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  150. mainBlock(^{
  151. [weakSelf showNetErrorAlertFun];
  152. [weakSelf enterMainVCFromSceneSecondStepFun];
  153. });
  154. });
  155. }
  156. else if(didSuc == 2
  157. ||didSuc == 201
  158. ||didSuc == 202){
  159. [weakSelf gotoScanAginByThridMsgErrorFun:didSuc];
  160. }
  161. else{
  162. [weakSelf enterMainVCFromSceneSecondStepFun];
  163. }
  164. }];
  165. }
  166. else{
  167. [self enterMainVCFromSceneSecondStepFun];
  168. }
  169. }
  170. - (void)enterMainVCFromSceneSecondStepFun
  171. {
  172. //确保通过SN号拿到密码了
  173. //非扫码进入 进入到这里很可能还没联网拿到设备最新信息
  174. if(![connectDeviceManager shareInstance].DeviceThirdIdMod){
  175. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  176. mainBlock(^{
  177. [self enterMainVCFromScene];
  178. });
  179. });
  180. return;
  181. }
  182. //是否已经有密码了 有就是输入密码 没有就是设置密码
  183. NSString *curPwd = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.password;
  184. NSString * sdnId = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.sdnId;
  185. if(!sdnId){
  186. HLog(@"没有拿到sdnId");
  187. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  188. mainBlock(^{
  189. [self enterMainVCFromScene];
  190. });
  191. });
  192. return;
  193. }
  194. if(_customLaunchV){
  195. [_customLaunchV removeFromSuperview];
  196. _customLaunchV = nil;
  197. }
  198. if(curPwd && curPwd.length > 0){
  199. /*设置密码*/
  200. // inputPWDViewController *nextVC = [[inputPWDViewController alloc] init];
  201. // BaseNavigationController *nextVCNav = [[BaseNavigationController alloc] initWithRootViewController:nextVC];
  202. // self.window.rootViewController = nextVCNav;
  203. }
  204. else{
  205. /*没有设置密码*/
  206. SetPWDFirstViewController *qrCodeVC = [[SetPWDFirstViewController alloc] init];
  207. BaseNavigationController *qrCodeVCNav = [[BaseNavigationController alloc] initWithRootViewController:qrCodeVC];
  208. self.window.rootViewController = qrCodeVCNav;
  209. return;
  210. }
  211. //下载配置先处理
  212. [boxDownloadFileManager shareInstance];
  213. if(_curPlayerVC){
  214. //[_curPlayerVC disconnectVideoServer];
  215. _curPlayerVC.isNeedRecyclResource = YES;
  216. [_curPlayerVC recyclResource];
  217. _curPlayerVC.liveStreamManager = nil;
  218. _curPlayerVC.commandChannelManager = nil;
  219. [_curPlayerVC.navigationController popViewControllerAnimated:NO];
  220. _curPlayerVC = nil;
  221. }
  222. //每次进入
  223. PlayerViewController *playerRootVC = [[PlayerViewController alloc] init];
  224. if(self.isLoginAgainType){
  225. playerRootVC.isLoginAgainType = self.isLoginAgainType;
  226. }
  227. playerRootVC.isPwdVCShow = YES;
  228. _curPlayerVC = playerRootVC;
  229. // BaseNavigationController *playerNav = [[BaseNavigationController alloc] initWithRootViewController:playerRootVC];
  230. // self.window.rootViewController = playerNav;
  231. UIViewController *vc = [UIViewController new];
  232. BaseNavigationController *playerNav = [[BaseNavigationController alloc] initWithRootViewController:vc];
  233. [playerNav pushViewController:playerRootVC animated:NO];
  234. self.window.rootViewController = playerNav;
  235. _preRootPlayerNav = playerNav;
  236. self.isLoginAgainType = NO;
  237. __block BOOL isPrivacyMode = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.isPrivacyMode;
  238. KWeakSelf
  239. if(!_isQRCodeType){
  240. if(isPrivacyMode)
  241. {
  242. [playerRootVC setShowImgAndVoiceTypeFun:NO];
  243. [self showCalculatorVC];
  244. }
  245. else{
  246. [self HandleEnterNotPrivacyModeFun];
  247. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  248. mainBlock(^{
  249. [connectDeviceManager shareInstance].isFirstInputPwdDone = YES;
  250. playerRootVC.isPwdVCShow = NO;
  251. [playerRootVC setShowImgAndVoiceTypeFun:YES];
  252. //[weakSelf shareAwakenAppBy:weakSelf.getShareStr];
  253. if(self->_session && self->_connectionOptions){
  254. [self scene:self->_session openURLContexts:self->_connectionOptions.URLContexts];
  255. }
  256. });
  257. });
  258. }
  259. //_isQRCodeType = NO;
  260. }
  261. else{
  262. if(isPrivacyMode)
  263. {
  264. [playerRootVC setShowImgAndVoiceTypeFun:NO];
  265. [self showCalculatorVC];
  266. }
  267. else{
  268. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  269. mainBlock(^{
  270. playerRootVC.isPwdVCShow = NO;
  271. [playerRootVC setShowImgAndVoiceTypeFun:YES];
  272. });
  273. });
  274. }
  275. }
  276. _isQRCodeType = NO;
  277. //获取NAS相关信息
  278. [self getNASMsgFun];
  279. }
  280. #pragma mark 处理进来是非隐私模式的情况
  281. - (void)HandleEnterNotPrivacyModeFun
  282. {
  283. #ifdef developJSQ
  284. NSInteger maskModel = 1;// [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  285. #else
  286. NSInteger maskModel = [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  287. #endif
  288. if (maskModel != 0){
  289. [HWDataManager setIntegerWithKey:Const_Mask_View_Model value:0];
  290. [iTools lc_setAlternateIconName:@"AppIcon1"];
  291. }
  292. }
  293. - (void)setPwdOk{
  294. [self enterMainVCFromScene];
  295. // NSArray *dataArray = [BaseModel bg_findAll:DB_BrowserWindows_TableName];
  296. //
  297. // if (dataArray.count == 0) { // 浏览器没有窗口
  298. // // 加载首页
  299. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  300. // vc.webUrl = Const_HomeUrl;
  301. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  302. // self.window.rootViewController = nvc;
  303. //
  304. // }else {
  305. // // 浏览器当前窗口索引ID
  306. // NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  307. // NSString *where = [NSString stringWithFormat:@"where %@=%ld",bg_sqlKey(@"ID"),(long)ID];
  308. // NSArray* finfAlls = [BaseModel bg_find:DB_BrowserWindows_TableName where:where];
  309. // BaseModel *model = finfAlls.firstObject;
  310. //
  311. // // 加载网页
  312. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  313. // vc.webUrl = model.webUrl;
  314. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  315. // self.window.rootViewController = nvc;
  316. // }
  317. }
  318. /** 登录界面 - 外部使用*/
  319. + (void)enterLoginVC {
  320. // SetPWDViewController *vc = [[SetPWDViewController alloc] init];
  321. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  322. // UIWindow *keyWindow = [iTools getKeyWindow];
  323. // keyWindow.rootViewController = nvc;
  324. }
  325. /** 主界面 - 外部使用 */
  326. + (void)enterMainVC {
  327. // AlbumHomeViewController *vc = [[AlbumHomeViewController alloc] init];
  328. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  329. // UIWindow *keyWindow = [iTools getKeyWindow];
  330. // keyWindow.rootViewController = nvc;
  331. }
  332. - (void)sceneDidDisconnect:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  333. HLog(@"sceneDidDisconnect");
  334. //[[boxDownloadFileManager shareInstance] suspendDownloadFileFun:YES withModel:nil withItem:nil];
  335. }
  336. - (void)sceneDidBecomeActive:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  337. // BOOL haveGuide = [HWDataManager getBoolWithKey:Const_Have_Show_Guide];
  338. // if (haveGuide) {
  339. // ;
  340. // }else {
  341. //
  342. // return;
  343. // }
  344. // [self showCalculatorVC];
  345. }
  346. - (void)sceneWillResignActive:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  347. BOOL haveGuide = [HWDataManager getBoolWithKey:Const_Have_Show_Guide];
  348. if (haveGuide) {
  349. ;
  350. }else {
  351. return;
  352. }
  353. [self showCalculatorVC];
  354. }
  355. - (void)sceneWillEnterForeground:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  356. }
  357. - (void)sceneDidEnterBackground:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  358. BOOL haveGuide = [HWDataManager getBoolWithKey:Const_Have_Show_Guide];
  359. if (haveGuide) {
  360. ;
  361. }else {
  362. return;
  363. }
  364. [self showCalculatorVC];
  365. }
  366. - (void)scene:(UIScene *)scene continueUserActivity:(NSUserActivity *)userActivity {
  367. if([TencentOAuth CanHandleUniversalLink:userActivity.webpageURL]){
  368. [TencentOAuth HandleUniversalLink:userActivity.webpageURL];
  369. }
  370. else{
  371. [WXApi handleOpenUniversalLink:userActivity delegate:self];
  372. }
  373. }
  374. - (void)scene:(UIScene *)scene openURLContexts:(NSSet<UIOpenURLContext *> *)URLContexts {
  375. NSEnumerator *enumerator = [URLContexts objectEnumerator];
  376. UIOpenURLContext *context;
  377. while (context = [enumerator nextObject]) {
  378. NSLog(@"context.URL =====%@",context.URL);
  379. //openprivacyxapp://page?param1=value1&param2=value2
  380. NSString *curStr = context.URL.absoluteString;
  381. if([curStr rangeOfString:@"openprivacyxapp://page"].location != NSNotFound){
  382. _getShareStr = curStr;
  383. [self delayedHandlShareAwakenAppBy:curStr];
  384. break;
  385. }
  386. else{
  387. [WXApi handleOpenURL:context.URL delegate:self];
  388. }
  389. //NSLog(@"context.options.sourceApplication ===== %@",context.options.sourceApplication);
  390. }
  391. _session = nil;
  392. _connectionOptions = nil;
  393. }
  394. - (void)delayedHandlShareAwakenAppBy:(NSString*)curStr{
  395. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  396. [self shareAwakenAppBy:curStr];
  397. });
  398. }
  399. #pragma mark 初始化数据库-DB_BrowserWindows_TableName
  400. - (void)initBrowserWindow {
  401. // 浏览器当前所有窗口
  402. NSArray *dataArray = [BaseModel bg_findAll:DB_BrowserWindows_TableName];
  403. // 浏览器当前窗口索引ID
  404. NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  405. NSString *IDValue = [NSString stringWithFormat:@"%ld", ID];
  406. NSString *where = [NSString stringWithFormat:@"where %@=%@",bg_sqlKey(@"ID"),bg_sqlValue(IDValue)];
  407. NSArray *modelArr = [BaseModel bg_find:DB_BrowserWindows_TableName where:where];
  408. if (dataArray.count == 0) { // 浏览器没有窗口
  409. BaseModel *model = [[BaseModel alloc] init];
  410. model.ID = 0;
  411. model.name = @"主页";
  412. // model.iconFile = imageUrl;
  413. model.webUrl = Const_HomeUrl;
  414. // 写入数据库
  415. model.bg_tableName = DB_BrowserWindows_TableName;
  416. [model bg_saveOrUpdateAsync:^(BOOL isSuccess) {
  417. HLog(@"BaseModel写入:%@", isSuccess ? @"成功":@"失败");
  418. }];
  419. // 浏览器当前窗口索引ID
  420. [HWDataManager setIntegerWithKey:BrowserWindowsCurrentID value:0];
  421. }else if (modelArr.count == 0) { // 新建窗口
  422. BaseModel *model = [[BaseModel alloc] init];
  423. model.ID = ID;
  424. model.name = @"主页";
  425. // model.iconFile = imageUrl;
  426. model.webUrl = Const_HomeUrl;
  427. // 写入数据库
  428. model.bg_tableName = DB_BrowserWindows_TableName;
  429. [model bg_saveOrUpdateAsync:^(BOOL isSuccess) {
  430. HLog(@"BaseModel写入:%@", isSuccess ? @"成功":@"失败");
  431. }];
  432. }else { // 更新窗口数据
  433. // 浏览器当前窗口索引ID
  434. // NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  435. //
  436. // BaseModel *model = [[BaseModel alloc] init];
  437. // model.ID = ID;
  438. // model.name = @"主页";
  439. //// model.iconFile = imageUrl;
  440. // model.webUrl = Const_HomeUrl;
  441. //
  442. // // 更新数据库
  443. // model.bg_tableName = DB_BrowserWindows_TableName;
  444. // [model bg_saveOrUpdateAsync:^(BOOL isSuccess) {
  445. // HLog(@"BaseModel更新: %@", isSuccess ? @"成功":@"失败");
  446. // }];
  447. }
  448. }
  449. #pragma mark 获取当前屏幕的截图
  450. //- (UIImage *)getScreenShotImage {
  451. // CGSize size = [UIScreen mainScreen].bounds.size;
  452. // CGFloat scale = [UIScreen mainScreen].scale;
  453. // UIGraphicsBeginImageContextWithOptions(size, YES, scale);
  454. // [self.window.layer renderInContext:UIGraphicsGetCurrentContext()];
  455. // UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
  456. // UIGraphicsEndImageContext();
  457. // return image;
  458. //}
  459. #pragma mark 计算器伪装视图
  460. /*CalculatorViewController*/
  461. - (void)showCalculatorVC{
  462. if(ksharedAppDelegate.getSystemPermissType){
  463. HLog(@"检测到获取系统全进入后台");
  464. return;
  465. }
  466. //修复扫描已经有密码的合作 点击跳过因为网络弹框再次覆盖一次密码(需要输入两次密码)
  467. BaseNavigationController*curTopNav = (BaseNavigationController*)[iTools appRootViewController];
  468. if([curTopNav isKindOfClass:[BaseNavigationController class]]){
  469. NSArray *vcArr = [curTopNav viewControllers];
  470. if(vcArr && vcArr.count >0){
  471. UIViewController *lastVC = vcArr.lastObject;
  472. if([lastVC isKindOfClass:[inputPWDViewController class]]){
  473. return;
  474. }
  475. }
  476. }
  477. /*无有效时长直接返回不加载任何加密界面*/
  478. NSString *PwdStr = nil;
  479. NSDictionary *deviceDict = [HWDataManager getObjectWithKey:Const_Have_Add_Device];
  480. //本地密码本地判断 密码改在服务器保持
  481. if ([[deviceDict allKeys] containsObject:Const_Have_Add_Device_PWD]){
  482. PwdStr = [deviceDict objectForKey:Const_Have_Add_Device_PWD];
  483. }
  484. //实时拿到的密码 (每次打开或者更换设备 通过SN重新拿)
  485. if([connectDeviceManager shareInstance].DeviceThirdIdMod.data.password){
  486. NSString *curPwd = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.password;
  487. NSString*desPwdStr = [RSATool AES128Decrypt:curPwd key:AESCODEKEEYY];
  488. if(desPwdStr){
  489. PwdStr = desPwdStr;
  490. }
  491. }
  492. if (!PwdStr || [PwdStr isEqualToString:@""])
  493. {
  494. return;
  495. }
  496. // BOOL haveOpenMask = [HWDataManager getBoolWithKey:Const_Mask_View_Open];
  497. // if (!haveOpenMask){
  498. // //输入密码界面
  499. // [self closeCalculatorVC];
  500. // _inputVC = [[inputPWDViewController alloc] init];
  501. // [self.window addSubview:_inputVC.view];
  502. // return;
  503. // }
  504. BOOL haveVaildTime = [HWDataManager getBoolWithKey:Const_Have_No_VaildTime];
  505. if (haveVaildTime == YES){/*无有效时间*/
  506. return;
  507. }
  508. if(![connectDeviceManager shareInstance].DeviceThirdIdMod){
  509. return;
  510. }
  511. BOOL isPrivacyMode = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.isPrivacyMode;
  512. if(!isPrivacyMode)
  513. {
  514. [connectDeviceManager shareInstance].isFirstInputPwdDone = YES;
  515. [[NSNotificationCenter defaultCenter] postNotificationName:ShowImgAndVoiceNotification object:nil];
  516. return;
  517. }
  518. #ifdef developJSQ
  519. NSInteger maskModel = 1;// [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  520. #else
  521. NSInteger maskModel = [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  522. #endif
  523. if (maskModel == 0){
  524. //输入密码界面
  525. [self closeCalculatorVC];
  526. _inputVC = [[inputPWDViewController alloc] init];
  527. [self.window addSubview:_inputVC.view];
  528. _isDidShowPwdType = YES;
  529. }
  530. else if (maskModel == 2){
  531. /*浏览器*/
  532. [self closeCalculatorVC];
  533. _webVC = [[HWWebViewController alloc] init];
  534. _webVC.pwd = PwdStr;
  535. _webVC.webUrl = @"https://baidu.com";
  536. [self.window addSubview:_webVC.view];
  537. _isDidShowPwdType = YES;
  538. }else{
  539. /*计算器*/
  540. [self closeCalculatorVC];
  541. _calculatorVC = [[CalculatorViewController alloc] init];
  542. _calculatorVC.pwd = PwdStr;
  543. [self.window addSubview:_calculatorVC.view];
  544. _isDidShowPwdType = YES;
  545. }
  546. [[NSNotificationCenter defaultCenter] postNotificationName:ShowPwdVCNotification object:nil];
  547. }
  548. - (void)closeCalculatorVC{
  549. ksharedAppDelegate.getSystemPermissType = NO;
  550. if (_calculatorVC){
  551. [_calculatorVC.view removeFromSuperview];
  552. }
  553. /*浏览器*/
  554. if (_webVC){
  555. [_webVC.view removeFromSuperview];
  556. }
  557. if(_inputVC){
  558. [_inputVC.view removeFromSuperview];
  559. }
  560. _isDidShowPwdType = NO;
  561. if(self->_session && self->_connectionOptions){
  562. [self scene:self->_session openURLContexts:self->_connectionOptions.URLContexts];
  563. }
  564. }
  565. - (NSString *)documentPathForAccount:(NSString *)account fileFolder:(NSString *)fileFolder {
  566. NSString *path = DocumentPath;
  567. if (account.length != 0) {
  568. path = [NSString stringWithFormat:@"%@/%@/",DocumentPath,account];
  569. }
  570. if ([fileFolder containsString:@"/"]) {
  571. NSString *path1 = [path stringByAppendingPathComponent:fileFolder];
  572. path1 = [path1 stringByDeletingLastPathComponent];
  573. NSError *error;
  574. if (![[NSFileManager defaultManager] fileExistsAtPath:path1]) {
  575. [[NSFileManager defaultManager] createDirectoryAtPath:path1 withIntermediateDirectories:YES attributes:nil error:&error];
  576. }
  577. }else{
  578. NSError *error;
  579. if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
  580. [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error];
  581. }
  582. }
  583. return [path stringByAppendingPathComponent:fileFolder];
  584. }
  585. - (void)startUseBtnBePressed{
  586. [self enterMainVCFromScene];
  587. // NSString *launchAppPWDPath = [self documentPathForAccount:@"" fileFolder:@"LaunchPWD"];
  588. // NSString *str = [[NSString alloc] initWithContentsOfFile:launchAppPWDPath encoding:(NSUTF8StringEncoding) error:nil];
  589. // if (!str || [str isEqualToString:@"0"])
  590. // {
  591. // SetUsePWDViewController *loginVC = [[SetUsePWDViewController alloc] init];
  592. // loginVC.delegate = self;
  593. // self.window.rootViewController = loginVC;
  594. //
  595. // return;
  596. // }
  597. //
  598. // NSArray *dataArray = [BaseModel bg_findAll:DB_BrowserWindows_TableName];
  599. //
  600. // if (dataArray.count == 0) { // 浏览器没有窗口
  601. // // 加载首页
  602. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  603. // vc.webUrl = Const_HomeUrl;
  604. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  605. // self.window.rootViewController = nvc;
  606. //
  607. // }else {
  608. // // 浏览器当前窗口索引ID
  609. // NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  610. // NSString *where = [NSString stringWithFormat:@"where %@=%ld",bg_sqlKey(@"ID"),(long)ID];
  611. // NSArray* finfAlls = [BaseModel bg_find:DB_BrowserWindows_TableName where:where];
  612. // BaseModel *model = finfAlls.firstObject;
  613. //
  614. // // 加载网页
  615. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  616. // vc.webUrl = model.webUrl;
  617. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  618. // self.window.rootViewController = nvc;
  619. // }
  620. }
  621. - (void)loginOk{
  622. [self enterMainVCFromScene];
  623. }
  624. - (void)guideOk:(NSNotification*)not{
  625. NSString *object = not.object;
  626. if(object && [object isEqualToString:@"isLoginAgainType"]){
  627. self.isLoginAgainType = YES;
  628. }
  629. [self enterMainVCFromScene];
  630. //clear下载和上传的已经获取的数据
  631. [[uploadFileManager shareInstance] suspendUploadFileFun:YES withModel:nil];
  632. [uploadFileManager shareInstance].databaseArr = [NSMutableArray new];
  633. [uploadFileManager shareInstance].fileModelDataArr = [NSMutableArray new];
  634. [uploadFileManager shareInstance].curUploadFileDataModel.curUploadStateType = uploadStateWait;
  635. [[downloadManager shareInstance] suspendDownloadFileFun:YES withModel:nil];
  636. [downloadManager shareInstance].databaseArr = [NSMutableArray new];
  637. [downloadManager shareInstance].downLoadFileModelDataArr = [NSMutableArray new];
  638. [[backupsFileManager shareInstance] suspendBackupsFileFun];
  639. //frp的下载
  640. [YCDownloadManager pauseAllDownloadTask];
  641. NSString *uid =[connectDeviceManager shareInstance].DeviceThirdIdMod.data.sn;
  642. if(uid){
  643. }
  644. else{
  645. uid = @"";
  646. }
  647. [YCDownloadManager updateUid:uid];
  648. }
  649. #pragma mark 上报版本号信息
  650. -(void)reportVersionInfoFun
  651. {
  652. NSMutableDictionary *paraDict = [NSMutableDictionary new];
  653. NSString *vers = [iPhone appVersion];
  654. if(vers){
  655. [paraDict setValue:vers forKey:@"iosClientVersionNumber"];
  656. }
  657. NSDictionary *deviceDict = [HWDataManager getObjectWithKey:Const_Have_Add_Device];
  658. if (deviceDict && [[deviceDict allKeys] containsObject:Const_Have_Add_Device_SN]){
  659. NSString*snStr = deviceDict[Const_Have_Add_Device_SN];
  660. if(snStr){
  661. [paraDict setValue:snStr forKey:@"sn"];
  662. }
  663. else{
  664. return;
  665. }
  666. }
  667. else{
  668. return;;
  669. }
  670. // KWeakSelf
  671. [[netWorkManager shareInstance] CommonPostCallBackCode:reportVersionInfo Parameters:paraDict success:^(id _Nonnull responseObject) {
  672. } failure:^(NSError * _Nonnull error) {
  673. }];
  674. }
  675. #pragma mark 获取NAS相关信息
  676. -(void)getNASMsgFun
  677. {
  678. NSMutableDictionary *paraDict = [NSMutableDictionary new];
  679. NSString *SNStr = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.changeSn;
  680. if(SNStr){
  681. [paraDict setValue:SNStr forKey:@"sn"];
  682. }
  683. else{
  684. return;;
  685. }
  686. KWeakSelf
  687. [[netWorkManager shareInstance] CommonGetWithCallBackCode:getIpFun Parameters:paraDict success:^(id _Nonnull responseObject){
  688. NASMsgModel *model = [[NASMsgModel alloc] initWithDictionary:responseObject error:nil];
  689. if(model){
  690. ksharedAppDelegate.NASMsgMod = model;
  691. }
  692. } failure:^(NSError * _Nonnull error) {
  693. }];
  694. }
  695. #pragma mark 主动上锁
  696. - (void)showLockViewFun:(NSNotification*)not
  697. {
  698. [self showCalculatorVC];
  699. }
  700. #pragma mark 进入设置密码
  701. //- (void)setPwdVCFun:(NSNotification*)not
  702. //{
  703. // _isNeedToShowSecretKey = YES;
  704. //}
  705. #pragma mark 忘记密码
  706. - (void)forgetPwdFun:(NSNotification*)not
  707. {
  708. /*忘记密码*/
  709. forgetPwdViewController *forgetPwdVC = [[forgetPwdViewController alloc] init];
  710. BaseNavigationController *forgetPwdVCNav = [[BaseNavigationController alloc] initWithRootViewController:forgetPwdVC];
  711. self.window.rootViewController = forgetPwdVCNav;
  712. }
  713. #pragma mark 忘记密码返回
  714. - (void)forgetPwdBackFun:(NSNotification*)not
  715. {
  716. // if(_preRootPlayerNav)
  717. // {
  718. // self.window.rootViewController = _preRootPlayerNav;
  719. // }
  720. // else{
  721. [self enterMainVCFromScene];
  722. //}
  723. [self showCalculatorVC];
  724. }
  725. #pragma mark 忘记密码设置密码完成
  726. - (void)forgetPwdDidSetPwdFun:(NSNotification*)not
  727. {
  728. // if(_preRootPlayerNav)
  729. // {
  730. // NSArray *vcArr = _preRootPlayerNav.viewControllers;
  731. // if(vcArr.count > 2){
  732. // [_preRootPlayerNav popToViewController:vcArr[1] animated:NO];
  733. // }
  734. // self.window.rootViewController = _preRootPlayerNav;
  735. // }
  736. // else{
  737. [self enterMainVCFromScene];
  738. //}
  739. [self closeCalculatorVC];
  740. _curPlayerVC.isPwdVCShow = NO;
  741. [_curPlayerVC setShowImgAndVoiceTypeFun:YES];
  742. [connectDeviceManager shareInstance].isFirstInputPwdDone = YES;
  743. }
  744. #pragma mark 扫码切换设备 scanChangeDeviceNotification
  745. - (void)scanChangeDeviceFun:(NSNotification*)not
  746. {
  747. TipsQRCodeForChangeDeviceViewController *nextVC = [[TipsQRCodeForChangeDeviceViewController alloc] init];
  748. nextVC.isRootVCType = YES;
  749. BaseNavigationController *nextNav = [[BaseNavigationController alloc] initWithRootViewController:nextVC];
  750. self.window.rootViewController = nextNav;
  751. }
  752. #pragma mark 扫码切换设备点击返回
  753. - (void)scanChangeDeviceBackFun:(NSNotification*)not
  754. {
  755. // if(_preRootPlayerNav)
  756. // {
  757. // self.window.rootViewController = _preRootPlayerNav;
  758. // }
  759. // else{
  760. [self enterMainVCFromScene];
  761. //}
  762. [self showCalculatorVC];
  763. }
  764. #pragma mark 网络异常弹框
  765. -(void)showNetErrorAlertFun
  766. {
  767. NSInteger maskModel = [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  768. if(maskModel !=0 && _isDidShowPwdType){
  769. return;
  770. }
  771. NSString *linkErrTip = NSLocalizedString(@"player_link_fail_tip_type9",nil);
  772. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable){
  773. linkErrTip = NSLocalizedString(@"player_link_fail_phone_Tips",nil);
  774. _isNeedToStopWork = YES;
  775. [self showNetErrorAlertType2Fun];
  776. return;
  777. }
  778. linkErrTip = [[NSString alloc] initWithFormat:@"[9]%@",linkErrTip];
  779. ComontAlretViewController *linkFailAlretVC= [[ComontAlretViewController alloc] initWithTiTle:nil
  780. msg:linkErrTip
  781. imageStr:nil
  782. cancelTitle:NSLocalizedString(@"single_sign_on_exit",nil)
  783. okTitle:NSLocalizedString(@"player_link_fail_tryAgain",nil) isOkBtnHighlight:YES
  784. didClickOk:^{
  785. //[self enterMainVCFromScene];
  786. } didClickCancel:^{
  787. exit(0);
  788. }];
  789. linkFailAlretVC.modalPresentationStyle = UIModalPresentationCustom;
  790. [self.window.rootViewController presentViewController:linkFailAlretVC animated:YES completion:^{
  791. linkFailAlretVC.view.superview.backgroundColor = [UIColor clearColor];
  792. }];
  793. }
  794. #pragma mark 网络异常弹框
  795. -(void)showNetErrorAlertType2Fun
  796. {
  797. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable){
  798. NSString * linkErrTip = NSLocalizedString(@"netWork_error_tip_content",nil);
  799. ComontAlretViewController *linkFailAlretVC= [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"netWork_error_tip_title",nil)
  800. msg:linkErrTip
  801. imageStr:nil
  802. cancelTitle:NSLocalizedString(@"single_sign_on_exit",nil)
  803. okTitle:nil isOkBtnHighlight:NO
  804. didClickOk:^{
  805. //[self enterMainVCFromScene];
  806. } didClickCancel:^{
  807. exit(0);
  808. }];
  809. linkFailAlretVC.modalPresentationStyle = UIModalPresentationCustom;
  810. self.window.rootViewController = [UIViewController new];
  811. [self.window.rootViewController presentViewController:linkFailAlretVC animated:YES completion:^{
  812. linkFailAlretVC.view.superview.backgroundColor = [UIColor clearColor];
  813. }];
  814. }
  815. }
  816. - (void)gotoScanAginByThridMsgErrorFun:(NSInteger)errorCode
  817. {
  818. /*扫码界面*/
  819. TipsQRCodeViewController *qrCodeVC = [[TipsQRCodeViewController alloc] init];
  820. qrCodeVC.isNeedToShowAleatType = YES;
  821. qrCodeVC.getSNMsgcode = errorCode;
  822. BaseNavigationController *qrCodeVCNav = [[BaseNavigationController alloc] initWithRootViewController:qrCodeVC];
  823. self.window.rootViewController = qrCodeVCNav;
  824. }
  825. #pragma mark 分享页面唤醒APP
  826. - (void)shareAwakenAppBy:(NSString*)shareStr
  827. {
  828. //[[iToast makeText:shareStr] show];
  829. NSArray * paraArr = [shareStr componentsSeparatedByString:@"&"];
  830. if(!paraArr || paraArr.count==0){
  831. return;
  832. }
  833. //type=save和download
  834. NSString *type = nil;
  835. NSString *fileIds = nil;
  836. NSString *extractionCode = nil;
  837. NSString *token = nil;
  838. for (NSString*objectStr in paraArr) {
  839. if([objectStr rangeOfString:@"type"].location != NSNotFound){
  840. NSArray * objectArr = [objectStr componentsSeparatedByString:@"="];
  841. if(objectArr.count == 2){
  842. type = objectArr.lastObject;
  843. continue;
  844. }
  845. }
  846. else if([objectStr rangeOfString:@"fileIds"].location != NSNotFound){
  847. NSArray * objectArr = [objectStr componentsSeparatedByString:@"="];
  848. if(objectArr.count == 2){
  849. fileIds = objectArr.lastObject;
  850. continue;
  851. }
  852. }
  853. else if([objectStr rangeOfString:@"extractionCode"].location != NSNotFound){
  854. NSArray * objectArr = [objectStr componentsSeparatedByString:@"="];
  855. if(objectArr.count == 2){
  856. extractionCode = objectArr.lastObject;
  857. continue;
  858. }
  859. }
  860. else if([objectStr rangeOfString:@"token"].location != NSNotFound){
  861. NSArray * objectArr = [objectStr componentsSeparatedByString:@"="];
  862. if(objectArr.count == 2){
  863. token = objectArr.lastObject;
  864. continue;
  865. }
  866. }
  867. }
  868. if(!type || type.length ==0){
  869. HLog(@"分享 type 获取错误");
  870. return;
  871. }
  872. if(!fileIds || fileIds.length ==0){
  873. HLog(@"分享 fileIds 获取错误");
  874. return;
  875. }
  876. if(!token || token.length ==0){
  877. HLog(@"分享 token 获取错误");
  878. return;
  879. }
  880. [self getShareOneFileListFunByToken:token withFileIds:fileIds withExtractionCode:extractionCode withType:type];
  881. }
  882. #pragma mark 分享信息重新获取
  883. - (void)getShareOneFileListFunByToken:(NSString*)token withFileIds:(NSString*)fileIds withExtractionCode:(NSString*)extractionCode withType:(NSString*)type
  884. {
  885. NSMutableDictionary*paraDict = [NSMutableDictionary new];
  886. fileIds = [fileIds stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  887. NSData *jsonData = [fileIds dataUsingEncoding:NSUTF8StringEncoding];;
  888. NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
  889. HLog(@"jsonArray:%@",jsonArray)
  890. if(!jsonArray){
  891. return;
  892. }
  893. [paraDict setValue:token forKey:@"token"];
  894. [paraDict setValue:jsonArray forKey:@"fileIdList"];
  895. [paraDict setValue:extractionCode forKey:@"extractionCode"];
  896. KWeakSelf
  897. [[netWorkManager shareInstance] CommonPostCallBackCode:queryOneShareInfoFun Parameters:paraDict success:^(id _Nonnull responseObject) {
  898. queryOneShareModel*model = [[queryOneShareModel alloc] initWithDictionary:responseObject error:nil];
  899. if(model && model.status == 0){
  900. weakSelf.getShareStr = nil;
  901. [weakSelf gotoVCByModel:model withType:type];
  902. }
  903. else{
  904. }
  905. } failure:^(NSError * _Nonnull error) {
  906. }];
  907. }
  908. #pragma mark 跳转
  909. - (void)gotoVCByModel:(queryOneShareModel*)model withType:(NSString*)type
  910. {
  911. if([type isEqualToString:@"save"]){
  912. [self saveFileToBoxFunBy:model];
  913. }
  914. else if([type isEqualToString:@"download"]){
  915. [self downloadFileToAppFunBy:model];
  916. }
  917. }
  918. #pragma mark 保存文件到盒子
  919. - (void)saveFileToBoxFunBy:(queryOneShareModel*)sharemodel
  920. {
  921. NSMutableDictionary*paraDict = [NSMutableDictionary new];
  922. NSMutableArray *pathArr = [NSMutableArray new];
  923. for (ShareFileDataModel*dataModel in sharemodel.data.fileListVOS){
  924. [pathArr addObject:dataModel.fileUrl];
  925. }
  926. if (pathArr) {
  927. NSString *jsonStr = [iTools toJsonStrWithArray:pathArr];
  928. if(jsonStr){
  929. [paraDict setValue:jsonStr forKey:@"urls"];
  930. }
  931. }
  932. NSString * boxSaveDefaultPath = [HWDataManager getStringWithKey:stringKeyAddSn(Const_box_save_default_path)];
  933. if(!boxSaveDefaultPath || boxSaveDefaultPath.length == 0){
  934. boxSaveDefaultPath = Const_default_save_path;
  935. [HWDataManager setStringWithKey:stringKeyAddSn(Const_box_save_default_path) value:boxSaveDefaultPath];
  936. }
  937. [paraDict setValue:boxSaveDefaultPath forKey:@"savePath"];
  938. KWeakSelf
  939. [[netWorkManager shareInstance] cloudPhoneGETCallBackCode:@"downFiles" Parameters:paraDict success:^(id _Nonnull responseObject) {
  940. SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
  941. if(model && model.status == 0){
  942. [weakSelf gotoUploadFileRecordVCFunByType:2 withModel:sharemodel];
  943. }
  944. } failure:^(NSError * _Nonnull error) {
  945. }];
  946. }
  947. #pragma mark 下载文件到手机
  948. - (void)downloadFileToAppFunBy:(queryOneShareModel*)sharemodel
  949. {
  950. [self gotoUploadFileRecordVCFunByType:1 withModel:sharemodel];
  951. }
  952. #pragma mark 跳转传输列表
  953. - (void)gotoUploadFileRecordVCFunByType:(NSInteger)type withModel:(queryOneShareModel*)sharemodel
  954. {
  955. KWeakSelf
  956. if(type == 2){
  957. [[boxSaveFileManager shareInstance] addBoxSaveRecordFunBy:sharemodel.data.fileListVOS complete:^(BOOL isSuccess) {
  958. if(isSuccess){
  959. mainBlock(^{
  960. [weakSelf gotoUploadFileRecordVCFunByType:type];
  961. });
  962. }
  963. }];
  964. }
  965. else if (type == 1){
  966. [[boxDownloadFileManager shareInstance] addBoxDownloadRecordFunBy:sharemodel.data.fileListVOS complete:^(BOOL isSuccess) {
  967. if(isSuccess){
  968. mainBlock(^{
  969. [weakSelf gotoUploadFileRecordVCFunByType:type];
  970. });
  971. }
  972. }];
  973. }
  974. }
  975. - (void)gotoUploadFileRecordVCFunByType:(NSInteger)type
  976. {
  977. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  978. vc.isReceiveType = type;
  979. if(_curPlayerVC){
  980. NSArray *vcArr = _curPlayerVC.navigationController.viewControllers;
  981. UIViewController *lastVC = vcArr.lastObject;
  982. if([lastVC isKindOfClass:[PlayerViewController class]]){
  983. [[UIApplication sharedApplication] setStatusBarHidden:NO];
  984. }
  985. else if([lastVC isKindOfClass:[uploadFileRecordViewController class]]){
  986. [_curPlayerVC.navigationController popViewControllerAnimated:NO];
  987. //[[UIApplication sharedApplication] setStatusBarHidden:NO];
  988. }
  989. [_curPlayerVC.navigationController pushViewController:vc animated:YES];
  990. _curPlayerVC.isNeedRecyclResource = NO;
  991. }
  992. }
  993. @end