SceneDelegate.m 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  1. //
  2. // SceneDelegate.m
  3. // 唔即云相册
  4. //
  5. // Created by 余衡武 on 2021/12/8.
  6. //
  7. #import "SceneDelegate.h"
  8. #import "HWWebViewController.h"
  9. #import "CalculatorViewController.h"
  10. #import "SetUsePWDViewController.h"
  11. #import "GuideViewController.h"
  12. #import "BaseNavigationController.h"
  13. #import "MySetViewController.h"
  14. #import "SafeForKey.h"
  15. #import "TipsQRCodeViewController.h"
  16. #import "SetPWDFirstViewController.h"
  17. #import "ConnectTestViewController.h"
  18. //#import "PlayerViewController.h"
  19. #import "connectDeviceManager.h"
  20. #import "inputPWDViewController.h"
  21. #import "customLaunchView.h"
  22. #import "RSATool.h"
  23. #import "forgetPwdViewController.h"
  24. #import "TipsQRCodeForChangeDeviceViewController.h"
  25. #import "AFNetworkReachabilityManager.h"
  26. #import "ComontAlretViewController.h"
  27. @interface SceneDelegate ()<SetUsePWDViewControllerDelegate,GuideViewControllerDelegate>
  28. @property(nonatomic, strong) CalculatorViewController *calculatorVC;
  29. @property(nonatomic, strong) HWWebViewController *webVC;
  30. @property(nonatomic, strong) inputPWDViewController *inputVC;
  31. @property(nonatomic, strong) NSTimer *checkSNDataTimer;//
  32. @property(nonatomic, strong) customLaunchView *customLaunchV;//
  33. //@property(nonatomic, strong) PlayerViewController *curPlayerVC;
  34. @property(nonatomic, strong) BaseNavigationController *preRootPlayerNav;
  35. @property(nonatomic, assign) bool isQRCodeType;//第一次 扫码进来的
  36. @property(nonatomic, assign) bool isNeedToShowSecretKey;//扫码进来的SN 没有密码 则需要显示秘钥
  37. @property (nonatomic, assign) BOOL isLoginAgainType;// 单点登录 点重新登录进来的
  38. @end
  39. @implementation SceneDelegate
  40. - (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions API_AVAILABLE(ios(13.0)){
  41. if (scene) {
  42. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(guideOk:) name:GuideOkNotification object:nil];
  43. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showLockViewFun:) name:lockBypwdNotification object:nil];
  44. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setPwdVCFun:) name:setPwdNotification object:nil];
  45. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(forgetPwdFun:) name:forgetPwdNotification object:nil];
  46. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(forgetPwdBackFun:) name:forgetPwdBackNotification object:nil];
  47. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(forgetPwdDidSetPwdFun:) name:forgetPwdDidSetNotification object:nil];
  48. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scanChangeDeviceFun:) name:scanChangeDeviceNotification object:nil];
  49. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scanChangeDeviceBackFun:) name:scanChangeDeviceBackNotification object:nil];
  50. UIWindowScene *windowScene = (UIWindowScene *)scene;
  51. self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
  52. self.window.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
  53. // 初始化数据库
  54. [self initBrowserWindow];
  55. // 加载主页面
  56. [self enterMainVCFromScene];
  57. //
  58. [self getNetWorkPopViewFun];
  59. [self.window makeKeyAndVisible];
  60. }
  61. }
  62. /** 进入登录界面 - 内部使用 */
  63. - (void)enterLoginVCFromScene {
  64. // UIViewController *vc = [[UIViewController alloc] init];
  65. // vc.view.backgroundColor = [UIColor redColor];
  66. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  67. // self.window.rootViewController = nvc;
  68. }
  69. /** 主界面 - 内部使用 */
  70. - (void)enterMainVCFromScene {
  71. // ConnectTestViewController *qrCodeVCNav = [[ConnectTestViewController alloc] init];
  72. // self.window.rootViewController = qrCodeVCNav;
  73. // return;/*临时测试*/
  74. /*先判断本地有无设备 无设备时需要先扫码添加设备*/
  75. NSDictionary *deviceDict = [HWDataManager getObjectWithKey:Const_Have_Add_Device];
  76. if (!deviceDict || ![[deviceDict allKeys] containsObject:Const_Have_Add_Device_SN]){
  77. /*扫码界面*/
  78. TipsQRCodeViewController *qrCodeVC = [[TipsQRCodeViewController alloc] init];
  79. BaseNavigationController *qrCodeVCNav = [[BaseNavigationController alloc] initWithRootViewController:qrCodeVC];
  80. self.window.rootViewController = qrCodeVCNav;
  81. _isQRCodeType = YES;
  82. return;
  83. }
  84. KWeakSelf
  85. //有设备了先去做链接准备 // 80bec9c5
  86. NSString *SNStr = deviceDict[@"Const_Have_Add_Device_SN"];
  87. NSString *sdnId = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.sdnId;
  88. if(SNStr && !sdnId){
  89. [[connectDeviceManager shareInstance] getThridMsgBySN:SNStr needReconnect:YES didNetEnd:^(bool didSuc) {
  90. if(!didSuc){
  91. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  92. mainBlock(^{
  93. [weakSelf showNetErrorAlertFun];
  94. });
  95. });
  96. }
  97. }];
  98. }
  99. // GuideViewController
  100. BOOL haveGuide = [HWDataManager getBoolWithKey:Const_Have_Show_Guide];
  101. if (haveGuide) {
  102. ;
  103. }else {
  104. GuideViewController *guiDeVC = [[GuideViewController alloc] init];
  105. guiDeVC.delegate = self;
  106. guiDeVC.sn = SNStr;
  107. self.window.rootViewController = guiDeVC;
  108. return;
  109. }
  110. // if (![[deviceDict allKeys] containsObject:Const_Have_Add_Device_PWD]){
  111. // /*没有设置密码*/
  112. // SetPWDFirstViewController *qrCodeVC = [[SetPWDFirstViewController alloc] init];
  113. // BaseNavigationController *qrCodeVCNav = [[BaseNavigationController alloc] initWithRootViewController:qrCodeVC];
  114. // self.window.rootViewController = qrCodeVCNav;
  115. //
  116. // return;
  117. // }
  118. //确保通过SN号拿到密码了
  119. //非扫码进入 进入到这里很可能还没联网拿到设备最新信息
  120. if(![connectDeviceManager shareInstance].DeviceThirdIdMod){
  121. if(!_checkSNDataTimer){
  122. _checkSNDataTimer = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(enterMainVCFromScene) userInfo:nil repeats:YES];
  123. //BOOL haveOpenMask = [HWDataManager getBoolWithKey:Const_Mask_View_Open];
  124. NSInteger maskModel = [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  125. //添加默认启动图片
  126. if(!_customLaunchV && maskModel == 0){
  127. _customLaunchV = [[customLaunchView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H)];
  128. [self.window addSubview:_customLaunchV];
  129. }
  130. }
  131. return;
  132. }
  133. if(_checkSNDataTimer){
  134. [_checkSNDataTimer invalidate];
  135. [_customLaunchV removeFromSuperview];
  136. _customLaunchV = nil;
  137. }
  138. //是否已经有密码了 有就是输入密码 没有就是设置密码
  139. NSString *curPwd = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.password;
  140. sdnId = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.sdnId;
  141. if(!sdnId){
  142. HLog(@"没有拿到sdnId");
  143. [[connectDeviceManager shareInstance] getThridMsgBySN:SNStr needReconnect:YES didNetEnd:^(bool didSuc) {
  144. if(didSuc){
  145. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  146. mainBlock(^{
  147. [self enterMainVCFromScene];
  148. });
  149. });
  150. }
  151. }];
  152. return;
  153. }
  154. if(curPwd && curPwd.length > 0){
  155. /*设置密码*/
  156. // inputPWDViewController *nextVC = [[inputPWDViewController alloc] init];
  157. // BaseNavigationController *nextVCNav = [[BaseNavigationController alloc] initWithRootViewController:nextVC];
  158. // self.window.rootViewController = nextVCNav;
  159. }
  160. else{
  161. /*没有设置密码*/
  162. SetPWDFirstViewController *qrCodeVC = [[SetPWDFirstViewController alloc] init];
  163. BaseNavigationController *qrCodeVCNav = [[BaseNavigationController alloc] initWithRootViewController:qrCodeVC];
  164. self.window.rootViewController = qrCodeVCNav;
  165. return;
  166. }
  167. if(_curPlayerVC){
  168. [_curPlayerVC disconnectVideoServer];
  169. [_curPlayerVC recyclResource];
  170. ///后续要清掉下面的代码
  171. [_curPlayerVC toStopRecoder];
  172. [_curPlayerVC toStopAudioRecoder];
  173. [_curPlayerVC removeNSNotification];
  174. //清空WebSocket连接
  175. [_curPlayerVC.commandChannelManager rc_close];
  176. // globalBlock(^{
  177. // [self->_curPlayerVC.liveStreamManager rc_release];
  178. // });
  179. /////////
  180. _curPlayerVC.liveStreamManager = nil;
  181. _curPlayerVC.commandChannelManager = nil;
  182. _curPlayerVC = nil;
  183. }
  184. //每次进入
  185. PlayerViewController *playerRootVC = [[PlayerViewController alloc] init];
  186. if(self.isLoginAgainType){
  187. playerRootVC.isLoginAgainType = self.isLoginAgainType;
  188. }
  189. playerRootVC.isPwdVCShow = YES;
  190. _curPlayerVC = playerRootVC;
  191. BaseNavigationController *playerNav = [[BaseNavigationController alloc] initWithRootViewController:playerRootVC];
  192. self.window.rootViewController = playerNav;
  193. _preRootPlayerNav = playerNav;
  194. self.isLoginAgainType = NO;
  195. if(!_isQRCodeType){
  196. __block BOOL isPrivacyMode = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.isPrivacyMode;
  197. if(isPrivacyMode)
  198. {
  199. [playerRootVC setShowImgAndVoiceTypeFun:NO];
  200. [self showCalculatorVC];
  201. }
  202. else{
  203. [self HandleEnterNotPrivacyModeFun];
  204. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  205. mainBlock(^{
  206. [connectDeviceManager shareInstance].isFirstInputPwdDone = YES;
  207. playerRootVC.isPwdVCShow = NO;
  208. [playerRootVC setShowImgAndVoiceTypeFun:YES];
  209. });
  210. });
  211. }
  212. _isQRCodeType = NO;
  213. }
  214. else{
  215. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  216. mainBlock(^{
  217. playerRootVC.isPwdVCShow = NO;
  218. [playerRootVC setShowImgAndVoiceTypeFun:YES];
  219. if(self->_isNeedToShowSecretKey){
  220. [playerRootVC showSecretkeyFun];
  221. }
  222. });
  223. });
  224. }
  225. //test code
  226. //[playerRootVC showSecretkeyFun];
  227. // MySetViewController *playerRootVC = [[MySetViewController alloc] init];
  228. // BaseNavigationController *playerNav = [[BaseNavigationController alloc] initWithRootViewController:playerRootVC];
  229. // self.window.rootViewController = playerNav;
  230. }
  231. #pragma mark 处理进来是非隐私模式的情况
  232. - (void)HandleEnterNotPrivacyModeFun
  233. {
  234. NSInteger maskModel = [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  235. if (maskModel != 0){
  236. [HWDataManager setIntegerWithKey:Const_Mask_View_Model value:0];
  237. [iTools lc_setAlternateIconName:@"AppIcon1"];
  238. }
  239. }
  240. - (void)setPwdOk{
  241. [self enterMainVCFromScene];
  242. // NSArray *dataArray = [BaseModel bg_findAll:DB_BrowserWindows_TableName];
  243. //
  244. // if (dataArray.count == 0) { // 浏览器没有窗口
  245. // // 加载首页
  246. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  247. // vc.webUrl = Const_HomeUrl;
  248. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  249. // self.window.rootViewController = nvc;
  250. //
  251. // }else {
  252. // // 浏览器当前窗口索引ID
  253. // NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  254. // NSString *where = [NSString stringWithFormat:@"where %@=%ld",bg_sqlKey(@"ID"),(long)ID];
  255. // NSArray* finfAlls = [BaseModel bg_find:DB_BrowserWindows_TableName where:where];
  256. // BaseModel *model = finfAlls.firstObject;
  257. //
  258. // // 加载网页
  259. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  260. // vc.webUrl = model.webUrl;
  261. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  262. // self.window.rootViewController = nvc;
  263. // }
  264. }
  265. /** 登录界面 - 外部使用*/
  266. + (void)enterLoginVC {
  267. // SetPWDViewController *vc = [[SetPWDViewController alloc] init];
  268. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  269. // UIWindow *keyWindow = [iTools getKeyWindow];
  270. // keyWindow.rootViewController = nvc;
  271. }
  272. /** 主界面 - 外部使用 */
  273. + (void)enterMainVC {
  274. // AlbumHomeViewController *vc = [[AlbumHomeViewController alloc] init];
  275. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  276. // UIWindow *keyWindow = [iTools getKeyWindow];
  277. // keyWindow.rootViewController = nvc;
  278. }
  279. - (void)sceneDidDisconnect:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  280. }
  281. - (void)sceneDidBecomeActive:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  282. // BOOL haveGuide = [HWDataManager getBoolWithKey:Const_Have_Show_Guide];
  283. // if (haveGuide) {
  284. // ;
  285. // }else {
  286. //
  287. // return;
  288. // }
  289. // [self showCalculatorVC];
  290. }
  291. - (void)sceneWillResignActive:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  292. BOOL haveGuide = [HWDataManager getBoolWithKey:Const_Have_Show_Guide];
  293. if (haveGuide) {
  294. ;
  295. }else {
  296. return;
  297. }
  298. [self showCalculatorVC];
  299. }
  300. - (void)sceneWillEnterForeground:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  301. }
  302. - (void)sceneDidEnterBackground:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  303. BOOL haveGuide = [HWDataManager getBoolWithKey:Const_Have_Show_Guide];
  304. if (haveGuide) {
  305. ;
  306. }else {
  307. return;
  308. }
  309. [self showCalculatorVC];
  310. }
  311. #pragma mark 初始化数据库-DB_BrowserWindows_TableName
  312. - (void)initBrowserWindow {
  313. // 浏览器当前所有窗口
  314. NSArray *dataArray = [BaseModel bg_findAll:DB_BrowserWindows_TableName];
  315. // 浏览器当前窗口索引ID
  316. NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  317. NSString *IDValue = [NSString stringWithFormat:@"%ld", ID];
  318. NSString *where = [NSString stringWithFormat:@"where %@=%@",bg_sqlKey(@"ID"),bg_sqlValue(IDValue)];
  319. NSArray *modelArr = [BaseModel bg_find:DB_BrowserWindows_TableName where:where];
  320. if (dataArray.count == 0) { // 浏览器没有窗口
  321. BaseModel *model = [[BaseModel alloc] init];
  322. model.ID = 0;
  323. model.name = @"主页";
  324. // model.iconFile = imageUrl;
  325. model.webUrl = Const_HomeUrl;
  326. // 写入数据库
  327. model.bg_tableName = DB_BrowserWindows_TableName;
  328. [model bg_saveOrUpdateAsync:^(BOOL isSuccess) {
  329. HLog(@"BaseModel写入:%@", isSuccess ? @"成功":@"失败");
  330. }];
  331. // 浏览器当前窗口索引ID
  332. [HWDataManager setIntegerWithKey:BrowserWindowsCurrentID value:0];
  333. }else if (modelArr.count == 0) { // 新建窗口
  334. BaseModel *model = [[BaseModel alloc] init];
  335. model.ID = ID;
  336. model.name = @"主页";
  337. // model.iconFile = imageUrl;
  338. model.webUrl = Const_HomeUrl;
  339. // 写入数据库
  340. model.bg_tableName = DB_BrowserWindows_TableName;
  341. [model bg_saveOrUpdateAsync:^(BOOL isSuccess) {
  342. HLog(@"BaseModel写入:%@", isSuccess ? @"成功":@"失败");
  343. }];
  344. }else { // 更新窗口数据
  345. // 浏览器当前窗口索引ID
  346. // NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  347. //
  348. // BaseModel *model = [[BaseModel alloc] init];
  349. // model.ID = ID;
  350. // model.name = @"主页";
  351. //// model.iconFile = imageUrl;
  352. // model.webUrl = Const_HomeUrl;
  353. //
  354. // // 更新数据库
  355. // model.bg_tableName = DB_BrowserWindows_TableName;
  356. // [model bg_saveOrUpdateAsync:^(BOOL isSuccess) {
  357. // HLog(@"BaseModel更新: %@", isSuccess ? @"成功":@"失败");
  358. // }];
  359. }
  360. }
  361. #pragma mark 获取当前屏幕的截图
  362. //- (UIImage *)getScreenShotImage {
  363. // CGSize size = [UIScreen mainScreen].bounds.size;
  364. // CGFloat scale = [UIScreen mainScreen].scale;
  365. // UIGraphicsBeginImageContextWithOptions(size, YES, scale);
  366. // [self.window.layer renderInContext:UIGraphicsGetCurrentContext()];
  367. // UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
  368. // UIGraphicsEndImageContext();
  369. // return image;
  370. //}
  371. #pragma mark 计算器伪装视图
  372. /*CalculatorViewController*/
  373. - (void)showCalculatorVC{
  374. /*无有效时长直接返回不加载任何加密界面*/
  375. NSString *PwdStr = nil;
  376. NSDictionary *deviceDict = [HWDataManager getObjectWithKey:Const_Have_Add_Device];
  377. //本地密码本地判断 密码改在服务器保持
  378. if ([[deviceDict allKeys] containsObject:Const_Have_Add_Device_PWD]){
  379. PwdStr = [deviceDict objectForKey:Const_Have_Add_Device_PWD];
  380. }
  381. //实时拿到的密码 (每次打开或者更换设备 通过SN重新拿)
  382. if([connectDeviceManager shareInstance].DeviceThirdIdMod.data.password){
  383. NSString *curPwd = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.password;
  384. NSString*desPwdStr = [RSATool AES128Decrypt:curPwd key:AESCODEKEEYY];
  385. if(desPwdStr){
  386. PwdStr = desPwdStr;
  387. }
  388. }
  389. if (!PwdStr || [PwdStr isEqualToString:@""])
  390. {
  391. return;
  392. }
  393. // BOOL haveOpenMask = [HWDataManager getBoolWithKey:Const_Mask_View_Open];
  394. // if (!haveOpenMask){
  395. // //输入密码界面
  396. // [self closeCalculatorVC];
  397. // _inputVC = [[inputPWDViewController alloc] init];
  398. // [self.window addSubview:_inputVC.view];
  399. // return;
  400. // }
  401. BOOL haveVaildTime = [HWDataManager getBoolWithKey:Const_Have_No_VaildTime];
  402. if (haveVaildTime == YES){/*无有效时间*/
  403. return;
  404. }
  405. if(![connectDeviceManager shareInstance].DeviceThirdIdMod){
  406. return;
  407. }
  408. BOOL isPrivacyMode = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.isPrivacyMode;
  409. if(!isPrivacyMode)
  410. {
  411. [connectDeviceManager shareInstance].isFirstInputPwdDone = YES;
  412. [[NSNotificationCenter defaultCenter] postNotificationName:ShowImgAndVoiceNotification object:nil];
  413. return;
  414. }
  415. NSInteger maskModel = [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  416. if (maskModel == 0){
  417. //输入密码界面
  418. [self closeCalculatorVC];
  419. _inputVC = [[inputPWDViewController alloc] init];
  420. [self.window addSubview:_inputVC.view];
  421. }
  422. else if (maskModel == 2){
  423. /*浏览器*/
  424. [self closeCalculatorVC];
  425. _webVC = [[HWWebViewController alloc] init];
  426. _webVC.pwd = PwdStr;
  427. _webVC.webUrl = @"https://baidu.com";
  428. [self.window addSubview:_webVC.view];
  429. }else{
  430. /*计算器*/
  431. [self closeCalculatorVC];
  432. _calculatorVC = [[CalculatorViewController alloc] init];
  433. _calculatorVC.pwd = PwdStr;
  434. [self.window addSubview:_calculatorVC.view];
  435. }
  436. [[NSNotificationCenter defaultCenter] postNotificationName:ShowPwdVCNotification object:nil];
  437. }
  438. - (void)closeCalculatorVC{
  439. if (_calculatorVC){
  440. [_calculatorVC.view removeFromSuperview];
  441. }
  442. /*浏览器*/
  443. if (_webVC){
  444. [_webVC.view removeFromSuperview];
  445. }
  446. if(_inputVC){
  447. [_inputVC.view removeFromSuperview];
  448. }
  449. }
  450. - (NSString *)documentPathForAccount:(NSString *)account fileFolder:(NSString *)fileFolder {
  451. NSString *path = DocumentPath;
  452. if (account.length != 0) {
  453. path = [NSString stringWithFormat:@"%@/%@/",DocumentPath,account];
  454. }
  455. if ([fileFolder containsString:@"/"]) {
  456. NSString *path1 = [path stringByAppendingPathComponent:fileFolder];
  457. path1 = [path1 stringByDeletingLastPathComponent];
  458. NSError *error;
  459. if (![[NSFileManager defaultManager] fileExistsAtPath:path1]) {
  460. [[NSFileManager defaultManager] createDirectoryAtPath:path1 withIntermediateDirectories:YES attributes:nil error:&error];
  461. }
  462. }else{
  463. NSError *error;
  464. if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
  465. [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error];
  466. }
  467. }
  468. return [path stringByAppendingPathComponent:fileFolder];
  469. }
  470. - (void)startUseBtnBePressed{
  471. [self enterMainVCFromScene];
  472. // NSString *launchAppPWDPath = [self documentPathForAccount:@"" fileFolder:@"LaunchPWD"];
  473. // NSString *str = [[NSString alloc] initWithContentsOfFile:launchAppPWDPath encoding:(NSUTF8StringEncoding) error:nil];
  474. // if (!str || [str isEqualToString:@"0"])
  475. // {
  476. // SetUsePWDViewController *loginVC = [[SetUsePWDViewController alloc] init];
  477. // loginVC.delegate = self;
  478. // self.window.rootViewController = loginVC;
  479. //
  480. // return;
  481. // }
  482. //
  483. // NSArray *dataArray = [BaseModel bg_findAll:DB_BrowserWindows_TableName];
  484. //
  485. // if (dataArray.count == 0) { // 浏览器没有窗口
  486. // // 加载首页
  487. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  488. // vc.webUrl = Const_HomeUrl;
  489. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  490. // self.window.rootViewController = nvc;
  491. //
  492. // }else {
  493. // // 浏览器当前窗口索引ID
  494. // NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  495. // NSString *where = [NSString stringWithFormat:@"where %@=%ld",bg_sqlKey(@"ID"),(long)ID];
  496. // NSArray* finfAlls = [BaseModel bg_find:DB_BrowserWindows_TableName where:where];
  497. // BaseModel *model = finfAlls.firstObject;
  498. //
  499. // // 加载网页
  500. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  501. // vc.webUrl = model.webUrl;
  502. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  503. // self.window.rootViewController = nvc;
  504. // }
  505. }
  506. - (void)loginOk{
  507. [self enterMainVCFromScene];
  508. }
  509. - (void)guideOk:(NSNotification*)not{
  510. NSString *object = not.object;
  511. if(object && [object isEqualToString:@"isLoginAgainType"]){
  512. self.isLoginAgainType = YES;
  513. }
  514. [self enterMainVCFromScene];
  515. }
  516. #pragma mark 调起系统网络允许
  517. -(void)getNetWorkPopViewFun
  518. {
  519. NSMutableDictionary *paraDict = [NSMutableDictionary new];
  520. // KWeakSelf
  521. [[netWorkManager shareInstance] CommonGetWithCallBackCode:@"" Parameters:paraDict success:^(id _Nonnull responseObject) {
  522. } failure:^(NSError * _Nonnull error) {
  523. }];
  524. }
  525. #pragma mark 主动上锁
  526. - (void)showLockViewFun:(NSNotification*)not
  527. {
  528. [self showCalculatorVC];
  529. }
  530. #pragma mark 进入设置密码
  531. - (void)setPwdVCFun:(NSNotification*)not
  532. {
  533. _isNeedToShowSecretKey = YES;
  534. }
  535. #pragma mark 忘记密码
  536. - (void)forgetPwdFun:(NSNotification*)not
  537. {
  538. /*忘记密码*/
  539. forgetPwdViewController *forgetPwdVC = [[forgetPwdViewController alloc] init];
  540. BaseNavigationController *forgetPwdVCNav = [[BaseNavigationController alloc] initWithRootViewController:forgetPwdVC];
  541. self.window.rootViewController = forgetPwdVCNav;
  542. }
  543. #pragma mark 忘记密码返回
  544. - (void)forgetPwdBackFun:(NSNotification*)not
  545. {
  546. if(_preRootPlayerNav)
  547. {
  548. self.window.rootViewController = _preRootPlayerNav;
  549. }
  550. else{
  551. [self enterMainVCFromScene];
  552. }
  553. [self showCalculatorVC];
  554. }
  555. #pragma mark 忘记密码设置密码完成
  556. - (void)forgetPwdDidSetPwdFun:(NSNotification*)not
  557. {
  558. if(_preRootPlayerNav)
  559. {
  560. self.window.rootViewController = _preRootPlayerNav;
  561. }
  562. else{
  563. [self enterMainVCFromScene];
  564. }
  565. [self closeCalculatorVC];
  566. _curPlayerVC.isPwdVCShow = NO;
  567. [_curPlayerVC setShowImgAndVoiceTypeFun:YES];
  568. [connectDeviceManager shareInstance].isFirstInputPwdDone = YES;
  569. }
  570. #pragma mark 扫码切换设备 scanChangeDeviceNotification
  571. - (void)scanChangeDeviceFun:(NSNotification*)not
  572. {
  573. TipsQRCodeForChangeDeviceViewController *nextVC = [[TipsQRCodeForChangeDeviceViewController alloc] init];
  574. nextVC.isRootVCType = YES;
  575. BaseNavigationController *nextNav = [[BaseNavigationController alloc] initWithRootViewController:nextVC];
  576. self.window.rootViewController = nextNav;
  577. }
  578. #pragma mark 扫码切换设备点击返回
  579. - (void)scanChangeDeviceBackFun:(NSNotification*)not
  580. {
  581. if(_preRootPlayerNav)
  582. {
  583. self.window.rootViewController = _preRootPlayerNav;
  584. }
  585. else{
  586. [self enterMainVCFromScene];
  587. }
  588. [self showCalculatorVC];
  589. }
  590. #pragma mark 网络异常弹框
  591. -(void)showNetErrorAlertFun
  592. {
  593. NSInteger maskModel = [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  594. if(maskModel !=0){
  595. return;
  596. }
  597. NSString *linkErrTip = NSLocalizedString(@"player_link_fail_couldPhone_Tips",nil);
  598. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable){
  599. linkErrTip = NSLocalizedString(@"player_link_fail_phone_Tips",nil);
  600. }
  601. linkErrTip = [[NSString alloc] initWithFormat:@"[9]%@",linkErrTip];
  602. ComontAlretViewController *linkFailAlretVC= [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"player_link_fail_title",nil)
  603. msg:linkErrTip
  604. imageStr:nil
  605. cancelTitle:NSLocalizedString(@"single_sign_on_exit",nil)
  606. okTitle:NSLocalizedString(@"player_link_fail_tryAgain",nil) isOkBtnHighlight:YES
  607. didClickOk:^{
  608. //[self enterMainVCFromScene];
  609. } didClickCancel:^{
  610. exit(0);
  611. }];
  612. linkFailAlretVC.modalPresentationStyle = UIModalPresentationCustom;
  613. [self.window.rootViewController presentViewController:linkFailAlretVC animated:YES completion:^{
  614. linkFailAlretVC.view.superview.backgroundColor = [UIColor clearColor];
  615. }];
  616. }
  617. @end