SceneDelegate.m 26 KB

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