SceneDelegate.m 32 KB

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