SceneDelegate.m 42 KB

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