SceneDelegate.m 30 KB

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