SceneDelegate.m 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  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. #import "uploadFileManager.h"
  28. #import "downloadManager.h"
  29. #import "backupsFileManager.h"
  30. @interface SceneDelegate ()<SetUsePWDViewControllerDelegate,GuideViewControllerDelegate>
  31. @property(nonatomic, strong) CalculatorViewController *calculatorVC;
  32. @property(nonatomic, strong) HWWebViewController *webVC;
  33. @property(nonatomic, strong) inputPWDViewController *inputVC;
  34. @property(nonatomic, strong) customLaunchView *customLaunchV;//
  35. //@property(nonatomic, strong) PlayerViewController *curPlayerVC;
  36. @property(nonatomic, strong) BaseNavigationController *preRootPlayerNav;
  37. @property(nonatomic, assign) bool isQRCodeType;//第一次 扫码进来的
  38. @property(nonatomic, assign) bool isNeedToShowSecretKey;//扫码进来的SN 没有密码 则需要显示秘钥
  39. @property (nonatomic, assign) BOOL isLoginAgainType;// 单点登录 点重新登录进来的
  40. @end
  41. @implementation SceneDelegate
  42. - (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions API_AVAILABLE(ios(13.0)){
  43. if (scene) {
  44. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(guideOk:) name:GuideOkNotification object:nil];
  45. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showLockViewFun:) name:lockBypwdNotification object:nil];
  46. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setPwdVCFun:) name:setPwdNotification object:nil];
  47. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(forgetPwdFun:) name:forgetPwdNotification object:nil];
  48. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(forgetPwdBackFun:) name:forgetPwdBackNotification object:nil];
  49. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(forgetPwdDidSetPwdFun:) name:forgetPwdDidSetNotification object:nil];
  50. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scanChangeDeviceFun:) name:scanChangeDeviceNotification object:nil];
  51. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scanChangeDeviceBackFun:) name:scanChangeDeviceBackNotification object:nil];
  52. UIWindowScene *windowScene = (UIWindowScene *)scene;
  53. self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
  54. self.window.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
  55. // 初始化数据库
  56. [self initBrowserWindow];
  57. // 加载主页面
  58. [self enterMainVCFromScene];
  59. //
  60. [self getNetWorkPopViewFun];
  61. [self.window makeKeyAndVisible];
  62. ksharedAppDelegate.window = self.window;
  63. }
  64. }
  65. /** 进入登录界面 - 内部使用 */
  66. - (void)enterLoginVCFromScene {
  67. // UIViewController *vc = [[UIViewController alloc] init];
  68. // vc.view.backgroundColor = [UIColor redColor];
  69. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  70. // self.window.rootViewController = nvc;
  71. }
  72. /** 主界面 - 内部使用 */
  73. - (void)enterMainVCFromScene {
  74. // ConnectTestViewController *qrCodeVCNav = [[ConnectTestViewController alloc] init];
  75. // self.window.rootViewController = qrCodeVCNav;
  76. // return;/*临时测试*/
  77. /*先判断本地有无设备 无设备时需要先扫码添加设备*/
  78. NSDictionary *deviceDict = [HWDataManager getObjectWithKey:Const_Have_Add_Device];
  79. if (!deviceDict || ![[deviceDict allKeys] containsObject:Const_Have_Add_Device_SN]){
  80. /*扫码界面*/
  81. TipsQRCodeViewController *qrCodeVC = [[TipsQRCodeViewController alloc] init];
  82. BaseNavigationController *qrCodeVCNav = [[BaseNavigationController alloc] initWithRootViewController:qrCodeVC];
  83. self.window.rootViewController = qrCodeVCNav;
  84. _isQRCodeType = YES;
  85. return;
  86. }
  87. [self getDeviceMsgInMainVCWith:deviceDict];
  88. NSString *SNStr = deviceDict[@"Const_Have_Add_Device_SN"];
  89. // GuideViewController
  90. BOOL haveGuide = [HWDataManager getBoolWithKey:Const_Have_Show_Guide];
  91. if (haveGuide) {
  92. ;
  93. }else {
  94. GuideViewController *guiDeVC = [[GuideViewController alloc] init];
  95. guiDeVC.delegate = self;
  96. guiDeVC.sn = SNStr;
  97. self.window.rootViewController = guiDeVC;
  98. return;
  99. }
  100. //BOOL haveOpenMask = [HWDataManager getBoolWithKey:Const_Mask_View_Open];
  101. NSInteger maskModel = [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  102. //添加默认启动图片
  103. if(!_customLaunchV && maskModel == 0){
  104. _customLaunchV = [[customLaunchView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H)];
  105. [self.window addSubview:_customLaunchV];
  106. }
  107. }
  108. - (void)getDeviceMsgInMainVCWith:(NSDictionary*)deviceDict
  109. {
  110. KWeakSelf
  111. //有设备了先去做链接准备 // 80bec9c5
  112. NSString *SNStr = deviceDict[@"Const_Have_Add_Device_SN"];
  113. NSString *sdnId = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.sdnId;
  114. if(SNStr && !sdnId){
  115. [[connectDeviceManager shareInstance] getThridMsgBySN:SNStr needReconnect:YES didNetEnd:^(NSInteger didSuc) {
  116. if(didSuc == 0){
  117. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  118. mainBlock(^{
  119. [weakSelf showNetErrorAlertFun];
  120. });
  121. });
  122. }
  123. [weakSelf enterMainVCFromSceneSecondStepFun];
  124. }];
  125. }
  126. else{
  127. [self enterMainVCFromSceneSecondStepFun];
  128. }
  129. }
  130. - (void)enterMainVCFromSceneSecondStepFun
  131. {
  132. //确保通过SN号拿到密码了
  133. //非扫码进入 进入到这里很可能还没联网拿到设备最新信息
  134. if(![connectDeviceManager shareInstance].DeviceThirdIdMod){
  135. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  136. mainBlock(^{
  137. [self enterMainVCFromScene];
  138. });
  139. });
  140. return;
  141. }
  142. if(_customLaunchV){
  143. [_customLaunchV removeFromSuperview];
  144. _customLaunchV = nil;
  145. }
  146. //是否已经有密码了 有就是输入密码 没有就是设置密码
  147. NSString *curPwd = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.password;
  148. NSString * sdnId = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.sdnId;
  149. if(!sdnId){
  150. HLog(@"没有拿到sdnId");
  151. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  152. mainBlock(^{
  153. [self enterMainVCFromScene];
  154. });
  155. });
  156. return;
  157. }
  158. if(curPwd && curPwd.length > 0){
  159. /*设置密码*/
  160. // inputPWDViewController *nextVC = [[inputPWDViewController alloc] init];
  161. // BaseNavigationController *nextVCNav = [[BaseNavigationController alloc] initWithRootViewController:nextVC];
  162. // self.window.rootViewController = nextVCNav;
  163. }
  164. else{
  165. /*没有设置密码*/
  166. SetPWDFirstViewController *qrCodeVC = [[SetPWDFirstViewController alloc] init];
  167. BaseNavigationController *qrCodeVCNav = [[BaseNavigationController alloc] initWithRootViewController:qrCodeVC];
  168. self.window.rootViewController = qrCodeVCNav;
  169. return;
  170. }
  171. if(_curPlayerVC){
  172. //[_curPlayerVC disconnectVideoServer];
  173. _curPlayerVC.isNeedRecyclResource = YES;
  174. [_curPlayerVC recyclResource];
  175. _curPlayerVC.liveStreamManager = nil;
  176. _curPlayerVC.commandChannelManager = nil;
  177. [_curPlayerVC.navigationController popViewControllerAnimated:NO];
  178. _curPlayerVC = nil;
  179. }
  180. //每次进入
  181. PlayerViewController *playerRootVC = [[PlayerViewController alloc] init];
  182. if(self.isLoginAgainType){
  183. playerRootVC.isLoginAgainType = self.isLoginAgainType;
  184. }
  185. playerRootVC.isPwdVCShow = YES;
  186. _curPlayerVC = playerRootVC;
  187. // BaseNavigationController *playerNav = [[BaseNavigationController alloc] initWithRootViewController:playerRootVC];
  188. // self.window.rootViewController = playerNav;
  189. UIViewController *vc = [UIViewController new];
  190. BaseNavigationController *playerNav = [[BaseNavigationController alloc] initWithRootViewController:vc];
  191. [playerNav pushViewController:playerRootVC animated:NO];
  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. _isQRCodeType = NO;
  226. }
  227. #pragma mark 处理进来是非隐私模式的情况
  228. - (void)HandleEnterNotPrivacyModeFun
  229. {
  230. NSInteger maskModel = [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  231. if (maskModel != 0){
  232. [HWDataManager setIntegerWithKey:Const_Mask_View_Model value:0];
  233. [iTools lc_setAlternateIconName:@"AppIcon1"];
  234. }
  235. }
  236. - (void)setPwdOk{
  237. [self enterMainVCFromScene];
  238. // NSArray *dataArray = [BaseModel bg_findAll:DB_BrowserWindows_TableName];
  239. //
  240. // if (dataArray.count == 0) { // 浏览器没有窗口
  241. // // 加载首页
  242. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  243. // vc.webUrl = Const_HomeUrl;
  244. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  245. // self.window.rootViewController = nvc;
  246. //
  247. // }else {
  248. // // 浏览器当前窗口索引ID
  249. // NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  250. // NSString *where = [NSString stringWithFormat:@"where %@=%ld",bg_sqlKey(@"ID"),(long)ID];
  251. // NSArray* finfAlls = [BaseModel bg_find:DB_BrowserWindows_TableName where:where];
  252. // BaseModel *model = finfAlls.firstObject;
  253. //
  254. // // 加载网页
  255. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  256. // vc.webUrl = model.webUrl;
  257. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  258. // self.window.rootViewController = nvc;
  259. // }
  260. }
  261. /** 登录界面 - 外部使用*/
  262. + (void)enterLoginVC {
  263. // SetPWDViewController *vc = [[SetPWDViewController alloc] init];
  264. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  265. // UIWindow *keyWindow = [iTools getKeyWindow];
  266. // keyWindow.rootViewController = nvc;
  267. }
  268. /** 主界面 - 外部使用 */
  269. + (void)enterMainVC {
  270. // AlbumHomeViewController *vc = [[AlbumHomeViewController alloc] init];
  271. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  272. // UIWindow *keyWindow = [iTools getKeyWindow];
  273. // keyWindow.rootViewController = nvc;
  274. }
  275. - (void)sceneDidDisconnect:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  276. }
  277. - (void)sceneDidBecomeActive:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  278. // BOOL haveGuide = [HWDataManager getBoolWithKey:Const_Have_Show_Guide];
  279. // if (haveGuide) {
  280. // ;
  281. // }else {
  282. //
  283. // return;
  284. // }
  285. // [self showCalculatorVC];
  286. }
  287. - (void)sceneWillResignActive:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  288. BOOL haveGuide = [HWDataManager getBoolWithKey:Const_Have_Show_Guide];
  289. if (haveGuide) {
  290. ;
  291. }else {
  292. return;
  293. }
  294. [self showCalculatorVC];
  295. }
  296. - (void)sceneWillEnterForeground:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  297. }
  298. - (void)sceneDidEnterBackground:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  299. BOOL haveGuide = [HWDataManager getBoolWithKey:Const_Have_Show_Guide];
  300. if (haveGuide) {
  301. ;
  302. }else {
  303. return;
  304. }
  305. [self showCalculatorVC];
  306. }
  307. #pragma mark 初始化数据库-DB_BrowserWindows_TableName
  308. - (void)initBrowserWindow {
  309. // 浏览器当前所有窗口
  310. NSArray *dataArray = [BaseModel bg_findAll:DB_BrowserWindows_TableName];
  311. // 浏览器当前窗口索引ID
  312. NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  313. NSString *IDValue = [NSString stringWithFormat:@"%ld", ID];
  314. NSString *where = [NSString stringWithFormat:@"where %@=%@",bg_sqlKey(@"ID"),bg_sqlValue(IDValue)];
  315. NSArray *modelArr = [BaseModel bg_find:DB_BrowserWindows_TableName where:where];
  316. if (dataArray.count == 0) { // 浏览器没有窗口
  317. BaseModel *model = [[BaseModel alloc] init];
  318. model.ID = 0;
  319. model.name = @"主页";
  320. // model.iconFile = imageUrl;
  321. model.webUrl = Const_HomeUrl;
  322. // 写入数据库
  323. model.bg_tableName = DB_BrowserWindows_TableName;
  324. [model bg_saveOrUpdateAsync:^(BOOL isSuccess) {
  325. HLog(@"BaseModel写入:%@", isSuccess ? @"成功":@"失败");
  326. }];
  327. // 浏览器当前窗口索引ID
  328. [HWDataManager setIntegerWithKey:BrowserWindowsCurrentID value:0];
  329. }else if (modelArr.count == 0) { // 新建窗口
  330. BaseModel *model = [[BaseModel alloc] init];
  331. model.ID = ID;
  332. model.name = @"主页";
  333. // model.iconFile = imageUrl;
  334. model.webUrl = Const_HomeUrl;
  335. // 写入数据库
  336. model.bg_tableName = DB_BrowserWindows_TableName;
  337. [model bg_saveOrUpdateAsync:^(BOOL isSuccess) {
  338. HLog(@"BaseModel写入:%@", isSuccess ? @"成功":@"失败");
  339. }];
  340. }else { // 更新窗口数据
  341. // 浏览器当前窗口索引ID
  342. // NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  343. //
  344. // BaseModel *model = [[BaseModel alloc] init];
  345. // model.ID = ID;
  346. // model.name = @"主页";
  347. //// model.iconFile = imageUrl;
  348. // model.webUrl = Const_HomeUrl;
  349. //
  350. // // 更新数据库
  351. // model.bg_tableName = DB_BrowserWindows_TableName;
  352. // [model bg_saveOrUpdateAsync:^(BOOL isSuccess) {
  353. // HLog(@"BaseModel更新: %@", isSuccess ? @"成功":@"失败");
  354. // }];
  355. }
  356. }
  357. #pragma mark 获取当前屏幕的截图
  358. //- (UIImage *)getScreenShotImage {
  359. // CGSize size = [UIScreen mainScreen].bounds.size;
  360. // CGFloat scale = [UIScreen mainScreen].scale;
  361. // UIGraphicsBeginImageContextWithOptions(size, YES, scale);
  362. // [self.window.layer renderInContext:UIGraphicsGetCurrentContext()];
  363. // UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
  364. // UIGraphicsEndImageContext();
  365. // return image;
  366. //}
  367. #pragma mark 计算器伪装视图
  368. /*CalculatorViewController*/
  369. - (void)showCalculatorVC{
  370. /*无有效时长直接返回不加载任何加密界面*/
  371. NSString *PwdStr = nil;
  372. NSDictionary *deviceDict = [HWDataManager getObjectWithKey:Const_Have_Add_Device];
  373. //本地密码本地判断 密码改在服务器保持
  374. if ([[deviceDict allKeys] containsObject:Const_Have_Add_Device_PWD]){
  375. PwdStr = [deviceDict objectForKey:Const_Have_Add_Device_PWD];
  376. }
  377. //实时拿到的密码 (每次打开或者更换设备 通过SN重新拿)
  378. if([connectDeviceManager shareInstance].DeviceThirdIdMod.data.password){
  379. NSString *curPwd = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.password;
  380. NSString*desPwdStr = [RSATool AES128Decrypt:curPwd key:AESCODEKEEYY];
  381. if(desPwdStr){
  382. PwdStr = desPwdStr;
  383. }
  384. }
  385. if (!PwdStr || [PwdStr isEqualToString:@""])
  386. {
  387. return;
  388. }
  389. // BOOL haveOpenMask = [HWDataManager getBoolWithKey:Const_Mask_View_Open];
  390. // if (!haveOpenMask){
  391. // //输入密码界面
  392. // [self closeCalculatorVC];
  393. // _inputVC = [[inputPWDViewController alloc] init];
  394. // [self.window addSubview:_inputVC.view];
  395. // return;
  396. // }
  397. BOOL haveVaildTime = [HWDataManager getBoolWithKey:Const_Have_No_VaildTime];
  398. if (haveVaildTime == YES){/*无有效时间*/
  399. return;
  400. }
  401. if(![connectDeviceManager shareInstance].DeviceThirdIdMod){
  402. return;
  403. }
  404. BOOL isPrivacyMode = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.isPrivacyMode;
  405. if(!isPrivacyMode)
  406. {
  407. [connectDeviceManager shareInstance].isFirstInputPwdDone = YES;
  408. [[NSNotificationCenter defaultCenter] postNotificationName:ShowImgAndVoiceNotification object:nil];
  409. return;
  410. }
  411. NSInteger maskModel = [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  412. if (maskModel == 0){
  413. //输入密码界面
  414. [self closeCalculatorVC];
  415. _inputVC = [[inputPWDViewController alloc] init];
  416. [self.window addSubview:_inputVC.view];
  417. }
  418. else if (maskModel == 2){
  419. /*浏览器*/
  420. [self closeCalculatorVC];
  421. _webVC = [[HWWebViewController alloc] init];
  422. _webVC.pwd = PwdStr;
  423. _webVC.webUrl = @"https://baidu.com";
  424. [self.window addSubview:_webVC.view];
  425. }else{
  426. /*计算器*/
  427. [self closeCalculatorVC];
  428. _calculatorVC = [[CalculatorViewController alloc] init];
  429. _calculatorVC.pwd = PwdStr;
  430. [self.window addSubview:_calculatorVC.view];
  431. }
  432. [[NSNotificationCenter defaultCenter] postNotificationName:ShowPwdVCNotification object:nil];
  433. }
  434. - (void)closeCalculatorVC{
  435. if (_calculatorVC){
  436. [_calculatorVC.view removeFromSuperview];
  437. }
  438. /*浏览器*/
  439. if (_webVC){
  440. [_webVC.view removeFromSuperview];
  441. }
  442. if(_inputVC){
  443. [_inputVC.view removeFromSuperview];
  444. }
  445. }
  446. - (NSString *)documentPathForAccount:(NSString *)account fileFolder:(NSString *)fileFolder {
  447. NSString *path = DocumentPath;
  448. if (account.length != 0) {
  449. path = [NSString stringWithFormat:@"%@/%@/",DocumentPath,account];
  450. }
  451. if ([fileFolder containsString:@"/"]) {
  452. NSString *path1 = [path stringByAppendingPathComponent:fileFolder];
  453. path1 = [path1 stringByDeletingLastPathComponent];
  454. NSError *error;
  455. if (![[NSFileManager defaultManager] fileExistsAtPath:path1]) {
  456. [[NSFileManager defaultManager] createDirectoryAtPath:path1 withIntermediateDirectories:YES attributes:nil error:&error];
  457. }
  458. }else{
  459. NSError *error;
  460. if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
  461. [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error];
  462. }
  463. }
  464. return [path stringByAppendingPathComponent:fileFolder];
  465. }
  466. - (void)startUseBtnBePressed{
  467. [self enterMainVCFromScene];
  468. // NSString *launchAppPWDPath = [self documentPathForAccount:@"" fileFolder:@"LaunchPWD"];
  469. // NSString *str = [[NSString alloc] initWithContentsOfFile:launchAppPWDPath encoding:(NSUTF8StringEncoding) error:nil];
  470. // if (!str || [str isEqualToString:@"0"])
  471. // {
  472. // SetUsePWDViewController *loginVC = [[SetUsePWDViewController alloc] init];
  473. // loginVC.delegate = self;
  474. // self.window.rootViewController = loginVC;
  475. //
  476. // return;
  477. // }
  478. //
  479. // NSArray *dataArray = [BaseModel bg_findAll:DB_BrowserWindows_TableName];
  480. //
  481. // if (dataArray.count == 0) { // 浏览器没有窗口
  482. // // 加载首页
  483. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  484. // vc.webUrl = Const_HomeUrl;
  485. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  486. // self.window.rootViewController = nvc;
  487. //
  488. // }else {
  489. // // 浏览器当前窗口索引ID
  490. // NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  491. // NSString *where = [NSString stringWithFormat:@"where %@=%ld",bg_sqlKey(@"ID"),(long)ID];
  492. // NSArray* finfAlls = [BaseModel bg_find:DB_BrowserWindows_TableName where:where];
  493. // BaseModel *model = finfAlls.firstObject;
  494. //
  495. // // 加载网页
  496. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  497. // vc.webUrl = model.webUrl;
  498. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  499. // self.window.rootViewController = nvc;
  500. // }
  501. }
  502. - (void)loginOk{
  503. [self enterMainVCFromScene];
  504. }
  505. - (void)guideOk:(NSNotification*)not{
  506. NSString *object = not.object;
  507. if(object && [object isEqualToString:@"isLoginAgainType"]){
  508. self.isLoginAgainType = YES;
  509. }
  510. [self enterMainVCFromScene];
  511. //clear下载和上传的已经获取的数据
  512. [uploadFileManager shareInstance].databaseArr = [NSMutableArray new];
  513. [downloadManager shareInstance].databaseArr = [NSMutableArray new];
  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 = [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. @end