SceneDelegate.m 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870
  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. [self showCalculatorVC];
  235. }
  236. else{
  237. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  238. mainBlock(^{
  239. playerRootVC.isPwdVCShow = NO;
  240. [playerRootVC setShowImgAndVoiceTypeFun:YES];
  241. });
  242. });
  243. }
  244. }
  245. _isQRCodeType = NO;
  246. }
  247. #pragma mark 处理进来是非隐私模式的情况
  248. - (void)HandleEnterNotPrivacyModeFun
  249. {
  250. #ifdef developJSQ
  251. NSInteger maskModel = 1;// [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  252. #else
  253. NSInteger maskModel = [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  254. #endif
  255. if (maskModel != 0){
  256. [HWDataManager setIntegerWithKey:Const_Mask_View_Model value:0];
  257. [iTools lc_setAlternateIconName:@"AppIcon1"];
  258. }
  259. }
  260. - (void)setPwdOk{
  261. [self enterMainVCFromScene];
  262. // NSArray *dataArray = [BaseModel bg_findAll:DB_BrowserWindows_TableName];
  263. //
  264. // if (dataArray.count == 0) { // 浏览器没有窗口
  265. // // 加载首页
  266. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  267. // vc.webUrl = Const_HomeUrl;
  268. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  269. // self.window.rootViewController = nvc;
  270. //
  271. // }else {
  272. // // 浏览器当前窗口索引ID
  273. // NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  274. // NSString *where = [NSString stringWithFormat:@"where %@=%ld",bg_sqlKey(@"ID"),(long)ID];
  275. // NSArray* finfAlls = [BaseModel bg_find:DB_BrowserWindows_TableName where:where];
  276. // BaseModel *model = finfAlls.firstObject;
  277. //
  278. // // 加载网页
  279. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  280. // vc.webUrl = model.webUrl;
  281. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  282. // self.window.rootViewController = nvc;
  283. // }
  284. }
  285. /** 登录界面 - 外部使用*/
  286. + (void)enterLoginVC {
  287. // SetPWDViewController *vc = [[SetPWDViewController alloc] init];
  288. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  289. // UIWindow *keyWindow = [iTools getKeyWindow];
  290. // keyWindow.rootViewController = nvc;
  291. }
  292. /** 主界面 - 外部使用 */
  293. + (void)enterMainVC {
  294. // AlbumHomeViewController *vc = [[AlbumHomeViewController alloc] init];
  295. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  296. // UIWindow *keyWindow = [iTools getKeyWindow];
  297. // keyWindow.rootViewController = nvc;
  298. }
  299. - (void)sceneDidDisconnect:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  300. }
  301. - (void)sceneDidBecomeActive:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  302. // BOOL haveGuide = [HWDataManager getBoolWithKey:Const_Have_Show_Guide];
  303. // if (haveGuide) {
  304. // ;
  305. // }else {
  306. //
  307. // return;
  308. // }
  309. // [self showCalculatorVC];
  310. }
  311. - (void)sceneWillResignActive:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  312. BOOL haveGuide = [HWDataManager getBoolWithKey:Const_Have_Show_Guide];
  313. if (haveGuide) {
  314. ;
  315. }else {
  316. return;
  317. }
  318. [self showCalculatorVC];
  319. }
  320. - (void)sceneWillEnterForeground:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  321. }
  322. - (void)sceneDidEnterBackground:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  323. BOOL haveGuide = [HWDataManager getBoolWithKey:Const_Have_Show_Guide];
  324. if (haveGuide) {
  325. ;
  326. }else {
  327. return;
  328. }
  329. [self showCalculatorVC];
  330. }
  331. #pragma mark 初始化数据库-DB_BrowserWindows_TableName
  332. - (void)initBrowserWindow {
  333. // 浏览器当前所有窗口
  334. NSArray *dataArray = [BaseModel bg_findAll:DB_BrowserWindows_TableName];
  335. // 浏览器当前窗口索引ID
  336. NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  337. NSString *IDValue = [NSString stringWithFormat:@"%ld", ID];
  338. NSString *where = [NSString stringWithFormat:@"where %@=%@",bg_sqlKey(@"ID"),bg_sqlValue(IDValue)];
  339. NSArray *modelArr = [BaseModel bg_find:DB_BrowserWindows_TableName where:where];
  340. if (dataArray.count == 0) { // 浏览器没有窗口
  341. BaseModel *model = [[BaseModel alloc] init];
  342. model.ID = 0;
  343. model.name = @"主页";
  344. // model.iconFile = imageUrl;
  345. model.webUrl = Const_HomeUrl;
  346. // 写入数据库
  347. model.bg_tableName = DB_BrowserWindows_TableName;
  348. [model bg_saveOrUpdateAsync:^(BOOL isSuccess) {
  349. HLog(@"BaseModel写入:%@", isSuccess ? @"成功":@"失败");
  350. }];
  351. // 浏览器当前窗口索引ID
  352. [HWDataManager setIntegerWithKey:BrowserWindowsCurrentID value:0];
  353. }else if (modelArr.count == 0) { // 新建窗口
  354. BaseModel *model = [[BaseModel alloc] init];
  355. model.ID = ID;
  356. model.name = @"主页";
  357. // model.iconFile = imageUrl;
  358. model.webUrl = Const_HomeUrl;
  359. // 写入数据库
  360. model.bg_tableName = DB_BrowserWindows_TableName;
  361. [model bg_saveOrUpdateAsync:^(BOOL isSuccess) {
  362. HLog(@"BaseModel写入:%@", isSuccess ? @"成功":@"失败");
  363. }];
  364. }else { // 更新窗口数据
  365. // 浏览器当前窗口索引ID
  366. // NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  367. //
  368. // BaseModel *model = [[BaseModel alloc] init];
  369. // model.ID = ID;
  370. // model.name = @"主页";
  371. //// model.iconFile = imageUrl;
  372. // model.webUrl = Const_HomeUrl;
  373. //
  374. // // 更新数据库
  375. // model.bg_tableName = DB_BrowserWindows_TableName;
  376. // [model bg_saveOrUpdateAsync:^(BOOL isSuccess) {
  377. // HLog(@"BaseModel更新: %@", isSuccess ? @"成功":@"失败");
  378. // }];
  379. }
  380. }
  381. #pragma mark 获取当前屏幕的截图
  382. //- (UIImage *)getScreenShotImage {
  383. // CGSize size = [UIScreen mainScreen].bounds.size;
  384. // CGFloat scale = [UIScreen mainScreen].scale;
  385. // UIGraphicsBeginImageContextWithOptions(size, YES, scale);
  386. // [self.window.layer renderInContext:UIGraphicsGetCurrentContext()];
  387. // UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
  388. // UIGraphicsEndImageContext();
  389. // return image;
  390. //}
  391. #pragma mark 计算器伪装视图
  392. /*CalculatorViewController*/
  393. - (void)showCalculatorVC{
  394. if(ksharedAppDelegate.getSystemPermissType){
  395. HLog(@"检测到获取系统全进入后台");
  396. return;
  397. }
  398. //修复扫描已经有密码的合作 点击跳过因为网络弹框再次覆盖一次密码(需要输入两次密码)
  399. BaseNavigationController*curTopNav = (BaseNavigationController*)[iTools appRootViewController];
  400. if([curTopNav isKindOfClass:[BaseNavigationController class]]){
  401. NSArray *vcArr = [curTopNav viewControllers];
  402. if(vcArr && vcArr.count >0){
  403. UIViewController *lastVC = vcArr.lastObject;
  404. if([lastVC isKindOfClass:[inputPWDViewController class]]){
  405. return;
  406. }
  407. }
  408. }
  409. /*无有效时长直接返回不加载任何加密界面*/
  410. NSString *PwdStr = nil;
  411. NSDictionary *deviceDict = [HWDataManager getObjectWithKey:Const_Have_Add_Device];
  412. //本地密码本地判断 密码改在服务器保持
  413. if ([[deviceDict allKeys] containsObject:Const_Have_Add_Device_PWD]){
  414. PwdStr = [deviceDict objectForKey:Const_Have_Add_Device_PWD];
  415. }
  416. //实时拿到的密码 (每次打开或者更换设备 通过SN重新拿)
  417. if([connectDeviceManager shareInstance].DeviceThirdIdMod.data.password){
  418. NSString *curPwd = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.password;
  419. NSString*desPwdStr = [RSATool AES128Decrypt:curPwd key:AESCODEKEEYY];
  420. if(desPwdStr){
  421. PwdStr = desPwdStr;
  422. }
  423. }
  424. if (!PwdStr || [PwdStr isEqualToString:@""])
  425. {
  426. return;
  427. }
  428. // BOOL haveOpenMask = [HWDataManager getBoolWithKey:Const_Mask_View_Open];
  429. // if (!haveOpenMask){
  430. // //输入密码界面
  431. // [self closeCalculatorVC];
  432. // _inputVC = [[inputPWDViewController alloc] init];
  433. // [self.window addSubview:_inputVC.view];
  434. // return;
  435. // }
  436. BOOL haveVaildTime = [HWDataManager getBoolWithKey:Const_Have_No_VaildTime];
  437. if (haveVaildTime == YES){/*无有效时间*/
  438. return;
  439. }
  440. if(![connectDeviceManager shareInstance].DeviceThirdIdMod){
  441. return;
  442. }
  443. BOOL isPrivacyMode = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.isPrivacyMode;
  444. if(!isPrivacyMode)
  445. {
  446. [connectDeviceManager shareInstance].isFirstInputPwdDone = YES;
  447. [[NSNotificationCenter defaultCenter] postNotificationName:ShowImgAndVoiceNotification object:nil];
  448. return;
  449. }
  450. #ifdef developJSQ
  451. NSInteger maskModel = 1;// [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  452. #else
  453. NSInteger maskModel = [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  454. #endif
  455. if (maskModel == 0){
  456. //输入密码界面
  457. [self closeCalculatorVC];
  458. _inputVC = [[inputPWDViewController alloc] init];
  459. [self.window addSubview:_inputVC.view];
  460. _isDidShowPwdType = YES;
  461. }
  462. else if (maskModel == 2){
  463. /*浏览器*/
  464. [self closeCalculatorVC];
  465. _webVC = [[HWWebViewController alloc] init];
  466. _webVC.pwd = PwdStr;
  467. _webVC.webUrl = @"https://baidu.com";
  468. [self.window addSubview:_webVC.view];
  469. _isDidShowPwdType = YES;
  470. }else{
  471. /*计算器*/
  472. [self closeCalculatorVC];
  473. _calculatorVC = [[CalculatorViewController alloc] init];
  474. _calculatorVC.pwd = PwdStr;
  475. [self.window addSubview:_calculatorVC.view];
  476. _isDidShowPwdType = YES;
  477. }
  478. [[NSNotificationCenter defaultCenter] postNotificationName:ShowPwdVCNotification object:nil];
  479. }
  480. - (void)closeCalculatorVC{
  481. ksharedAppDelegate.getSystemPermissType = NO;
  482. if (_calculatorVC){
  483. [_calculatorVC.view removeFromSuperview];
  484. }
  485. /*浏览器*/
  486. if (_webVC){
  487. [_webVC.view removeFromSuperview];
  488. }
  489. if(_inputVC){
  490. [_inputVC.view removeFromSuperview];
  491. }
  492. _isDidShowPwdType = NO;
  493. }
  494. - (NSString *)documentPathForAccount:(NSString *)account fileFolder:(NSString *)fileFolder {
  495. NSString *path = DocumentPath;
  496. if (account.length != 0) {
  497. path = [NSString stringWithFormat:@"%@/%@/",DocumentPath,account];
  498. }
  499. if ([fileFolder containsString:@"/"]) {
  500. NSString *path1 = [path stringByAppendingPathComponent:fileFolder];
  501. path1 = [path1 stringByDeletingLastPathComponent];
  502. NSError *error;
  503. if (![[NSFileManager defaultManager] fileExistsAtPath:path1]) {
  504. [[NSFileManager defaultManager] createDirectoryAtPath:path1 withIntermediateDirectories:YES attributes:nil error:&error];
  505. }
  506. }else{
  507. NSError *error;
  508. if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
  509. [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error];
  510. }
  511. }
  512. return [path stringByAppendingPathComponent:fileFolder];
  513. }
  514. - (void)startUseBtnBePressed{
  515. [self enterMainVCFromScene];
  516. // NSString *launchAppPWDPath = [self documentPathForAccount:@"" fileFolder:@"LaunchPWD"];
  517. // NSString *str = [[NSString alloc] initWithContentsOfFile:launchAppPWDPath encoding:(NSUTF8StringEncoding) error:nil];
  518. // if (!str || [str isEqualToString:@"0"])
  519. // {
  520. // SetUsePWDViewController *loginVC = [[SetUsePWDViewController alloc] init];
  521. // loginVC.delegate = self;
  522. // self.window.rootViewController = loginVC;
  523. //
  524. // return;
  525. // }
  526. //
  527. // NSArray *dataArray = [BaseModel bg_findAll:DB_BrowserWindows_TableName];
  528. //
  529. // if (dataArray.count == 0) { // 浏览器没有窗口
  530. // // 加载首页
  531. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  532. // vc.webUrl = Const_HomeUrl;
  533. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  534. // self.window.rootViewController = nvc;
  535. //
  536. // }else {
  537. // // 浏览器当前窗口索引ID
  538. // NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  539. // NSString *where = [NSString stringWithFormat:@"where %@=%ld",bg_sqlKey(@"ID"),(long)ID];
  540. // NSArray* finfAlls = [BaseModel bg_find:DB_BrowserWindows_TableName where:where];
  541. // BaseModel *model = finfAlls.firstObject;
  542. //
  543. // // 加载网页
  544. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  545. // vc.webUrl = model.webUrl;
  546. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  547. // self.window.rootViewController = nvc;
  548. // }
  549. }
  550. - (void)loginOk{
  551. [self enterMainVCFromScene];
  552. }
  553. - (void)guideOk:(NSNotification*)not{
  554. NSString *object = not.object;
  555. if(object && [object isEqualToString:@"isLoginAgainType"]){
  556. self.isLoginAgainType = YES;
  557. }
  558. [self enterMainVCFromScene];
  559. //clear下载和上传的已经获取的数据
  560. [[uploadFileManager shareInstance] suspendUploadFileFun:YES];
  561. [uploadFileManager shareInstance].databaseArr = [NSMutableArray new];
  562. [uploadFileManager shareInstance].fileModelDataArr = [NSMutableArray new];
  563. [uploadFileManager shareInstance].curUploadFileDataModel.curUploadStateType = uploadStateWait;
  564. [[downloadManager shareInstance] suspendDownloadFileFun:YES];
  565. [downloadManager shareInstance].databaseArr = [NSMutableArray new];
  566. [downloadManager shareInstance].downLoadFileModelDataArr = [NSMutableArray new];
  567. [[backupsFileManager shareInstance] suspendBackupsFileFun];
  568. }
  569. #pragma mark 调起系统网络允许
  570. -(void)getNetWorkPopViewFun
  571. {
  572. NSMutableDictionary *paraDict = [NSMutableDictionary new];
  573. // KWeakSelf
  574. [[netWorkManager shareInstance] CommonGetWithCallBackCode:@"" Parameters:paraDict success:^(id _Nonnull responseObject) {
  575. } failure:^(NSError * _Nonnull error) {
  576. }];
  577. }
  578. #pragma mark 主动上锁
  579. - (void)showLockViewFun:(NSNotification*)not
  580. {
  581. [self showCalculatorVC];
  582. }
  583. #pragma mark 进入设置密码
  584. //- (void)setPwdVCFun:(NSNotification*)not
  585. //{
  586. // _isNeedToShowSecretKey = YES;
  587. //}
  588. #pragma mark 忘记密码
  589. - (void)forgetPwdFun:(NSNotification*)not
  590. {
  591. /*忘记密码*/
  592. forgetPwdViewController *forgetPwdVC = [[forgetPwdViewController alloc] init];
  593. BaseNavigationController *forgetPwdVCNav = [[BaseNavigationController alloc] initWithRootViewController:forgetPwdVC];
  594. self.window.rootViewController = forgetPwdVCNav;
  595. }
  596. #pragma mark 忘记密码返回
  597. - (void)forgetPwdBackFun:(NSNotification*)not
  598. {
  599. // if(_preRootPlayerNav)
  600. // {
  601. // self.window.rootViewController = _preRootPlayerNav;
  602. // }
  603. // else{
  604. [self enterMainVCFromScene];
  605. //}
  606. [self showCalculatorVC];
  607. }
  608. #pragma mark 忘记密码设置密码完成
  609. - (void)forgetPwdDidSetPwdFun:(NSNotification*)not
  610. {
  611. // if(_preRootPlayerNav)
  612. // {
  613. // NSArray *vcArr = _preRootPlayerNav.viewControllers;
  614. // if(vcArr.count > 2){
  615. // [_preRootPlayerNav popToViewController:vcArr[1] animated:NO];
  616. // }
  617. // self.window.rootViewController = _preRootPlayerNav;
  618. // }
  619. // else{
  620. [self enterMainVCFromScene];
  621. //}
  622. [self closeCalculatorVC];
  623. _curPlayerVC.isPwdVCShow = NO;
  624. [_curPlayerVC setShowImgAndVoiceTypeFun:YES];
  625. [connectDeviceManager shareInstance].isFirstInputPwdDone = YES;
  626. }
  627. #pragma mark 扫码切换设备 scanChangeDeviceNotification
  628. - (void)scanChangeDeviceFun:(NSNotification*)not
  629. {
  630. TipsQRCodeForChangeDeviceViewController *nextVC = [[TipsQRCodeForChangeDeviceViewController alloc] init];
  631. nextVC.isRootVCType = YES;
  632. BaseNavigationController *nextNav = [[BaseNavigationController alloc] initWithRootViewController:nextVC];
  633. self.window.rootViewController = nextNav;
  634. }
  635. #pragma mark 扫码切换设备点击返回
  636. - (void)scanChangeDeviceBackFun:(NSNotification*)not
  637. {
  638. // if(_preRootPlayerNav)
  639. // {
  640. // self.window.rootViewController = _preRootPlayerNav;
  641. // }
  642. // else{
  643. [self enterMainVCFromScene];
  644. //}
  645. [self showCalculatorVC];
  646. }
  647. #pragma mark 网络异常弹框
  648. -(void)showNetErrorAlertFun
  649. {
  650. NSInteger maskModel = [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  651. if(maskModel !=0 && _isDidShowPwdType){
  652. return;
  653. }
  654. NSString *linkErrTip = NSLocalizedString(@"player_link_fail_couldPhone_Tips",nil);
  655. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable){
  656. linkErrTip = NSLocalizedString(@"player_link_fail_phone_Tips",nil);
  657. _isNeedToStopWork = YES;
  658. [self showNetErrorAlertType2Fun];
  659. return;
  660. }
  661. linkErrTip = [[NSString alloc] initWithFormat:@"[9]%@",linkErrTip];
  662. ComontAlretViewController *linkFailAlretVC= [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"player_link_fail_title",nil)
  663. msg:linkErrTip
  664. imageStr:nil
  665. cancelTitle:NSLocalizedString(@"single_sign_on_exit",nil)
  666. okTitle:NSLocalizedString(@"player_link_fail_tryAgain",nil) isOkBtnHighlight:YES
  667. didClickOk:^{
  668. //[self enterMainVCFromScene];
  669. } didClickCancel:^{
  670. exit(0);
  671. }];
  672. linkFailAlretVC.modalPresentationStyle = UIModalPresentationCustom;
  673. [self.window.rootViewController presentViewController:linkFailAlretVC animated:YES completion:^{
  674. linkFailAlretVC.view.superview.backgroundColor = [UIColor clearColor];
  675. }];
  676. }
  677. #pragma mark 网络异常弹框
  678. -(void)showNetErrorAlertType2Fun
  679. {
  680. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable){
  681. NSString * linkErrTip = NSLocalizedString(@"netWork_error_tip_content",nil);
  682. ComontAlretViewController *linkFailAlretVC= [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"netWork_error_tip_title",nil)
  683. msg:linkErrTip
  684. imageStr:nil
  685. cancelTitle:NSLocalizedString(@"single_sign_on_exit",nil)
  686. okTitle:nil isOkBtnHighlight:NO
  687. didClickOk:^{
  688. //[self enterMainVCFromScene];
  689. } didClickCancel:^{
  690. exit(0);
  691. }];
  692. linkFailAlretVC.modalPresentationStyle = UIModalPresentationCustom;
  693. self.window.rootViewController = [UIViewController new];
  694. [self.window.rootViewController presentViewController:linkFailAlretVC animated:YES completion:^{
  695. linkFailAlretVC.view.superview.backgroundColor = [UIColor clearColor];
  696. }];
  697. }
  698. }
  699. - (void)gotoScanAginByThridMsgErrorFun
  700. {
  701. /*扫码界面*/
  702. TipsQRCodeViewController *qrCodeVC = [[TipsQRCodeViewController alloc] init];
  703. qrCodeVC.isNeedToShowAleatType = YES;
  704. BaseNavigationController *qrCodeVCNav = [[BaseNavigationController alloc] initWithRootViewController:qrCodeVC];
  705. self.window.rootViewController = qrCodeVCNav;
  706. }
  707. @end