SceneDelegate.m 45 KB

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