SceneDelegate.m 46 KB

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