SceneDelegate.m 33 KB

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