SceneDelegate.m 30 KB

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