SceneDelegate.m 31 KB

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