SceneDelegate.m 45 KB

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