SceneDelegate.m 27 KB

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