SceneDelegate.m 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437
  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 "connectDeviceManager.h"
  18. #import "inputPWDViewController.h"
  19. #import "customLaunchView.h"
  20. #import "RSATool.h"
  21. #import "forgetPwdViewController.h"
  22. #import "TipsQRCodeForChangeDeviceViewController.h"
  23. #import "AFNetworkReachabilityManager.h"
  24. #import "ComontAlretViewController.h"
  25. #import "uploadFileManager.h"
  26. #import "downloadManager.h"
  27. #import "backupsFileManager.h"
  28. #import "iPhone.h"
  29. #import <WXApi.h>
  30. #import <TencentOpenAPI/QQApiInterface.h>
  31. #import <TencentOpenAPI/TencentOAuth.h>
  32. #import "NASMsgModel.h"
  33. #import "queryOneShareModel.h"
  34. #import "boxSaveFileManager.h"
  35. #import "boxDownloadFileManager.h"
  36. #import "NASViewController.h"
  37. #import "cloudPhoneViewController.h"
  38. #import "mineViewController.h"
  39. #import "lastFileManager.h"
  40. #import "customDownloadManager.h"
  41. #import "audioPlayListManager.h"
  42. #import "QRCodeScanForChangeDeviceViewController.h"
  43. #import "customToastVew.h"
  44. #import "DFPlayer.h"
  45. @interface SceneDelegate ()<SetUsePWDViewControllerDelegate,GuideViewControllerDelegate,UITabBarControllerDelegate>
  46. @property(nonatomic, strong) CalculatorViewController *calculatorVC;
  47. @property(nonatomic, strong) HWWebViewController *webVC;
  48. @property(nonatomic, strong) inputPWDViewController *inputVC;
  49. @property(nonatomic, strong) customLaunchView *customLaunchV;//
  50. //@property(nonatomic, strong) PlayerViewController *curPlayerVC;
  51. @property(nonatomic, strong) BaseNavigationController *preRootPlayerNav;
  52. @property(nonatomic, assign) bool isQRCodeType;//第一次 扫码进来的
  53. //@property(nonatomic, assign) bool isNeedToShowSecretKey;//扫码进来的SN 没有密码 则需要显示秘钥
  54. @property (nonatomic, assign) BOOL isLoginAgainType;// 单点登录 点重新登录进来的
  55. @property (nonatomic, assign) BOOL isNeedToStopWork;// 无网络报错
  56. @property (nonatomic, assign) BOOL isDidShowPwdType;// 是否显示密码界面了
  57. @property(nonatomic, copy) NSString *getShareStr;//拿到分享的字符串
  58. @property (nonatomic, assign) BOOL isFirstOpenInLaunch;//启动页停两秒
  59. @property (nonatomic, assign) NSTimeInterval preEnterBackgroundTime;//记录盒子的的后台时间 用来控制进入后台一秒内回到前台不显示密码界面 (点击底部区域或下滑操作,返回输入密码界面)
  60. //冷启动分享跳入用
  61. @property(nonatomic, strong) UISceneSession *session;
  62. @property(nonatomic, strong) UISceneConnectionOptions *connectionOptions;
  63. @end
  64. @implementation SceneDelegate
  65. - (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions API_AVAILABLE(ios(13.0)){
  66. if (scene) {
  67. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(guideOk:) name:GuideOkNotification object:nil];
  68. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showLockViewFun:) name:lockBypwdNotification object:nil];
  69. //[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setPwdVCFun:) name:setPwdNotification object:nil];
  70. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(forgetPwdFun:) name:forgetPwdNotification object:nil];
  71. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(forgetPwdBackFun:) name:forgetPwdBackNotification object:nil];
  72. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(forgetPwdDidSetPwdFun:) name:forgetPwdDidSetNotification object:nil];
  73. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scanChangeDeviceFun:) name:scanChangeDeviceNotification object:nil];
  74. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scanChangeDeviceBackFun:) name:scanChangeDeviceBackNotification object:nil];
  75. UIWindowScene *windowScene = (UIWindowScene *)scene;
  76. self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
  77. self.window.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
  78. _isFirstOpenInLaunch = YES;
  79. // 初始化数据库
  80. [self initBrowserWindow];
  81. // 加载主页面
  82. [self enterMainVCFromScene];
  83. //
  84. [self reportVersionInfoFun];
  85. [self.window makeKeyAndVisible];
  86. ksharedAppDelegate.window = self.window;
  87. //冷启动
  88. if(connectionOptions.URLContexts != nil){
  89. _session = session;
  90. _connectionOptions = connectionOptions;
  91. // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  92. // mainBlock(^{
  93. // [self scene:scene openURLContexts:connectionOptions.URLContexts];
  94. // });
  95. // });
  96. }
  97. }
  98. }
  99. /** 主界面 - 内部使用 */
  100. - (void)enterMainVCFromScene {
  101. // ConnectTestViewController *qrCodeVCNav = [[ConnectTestViewController alloc] init];
  102. // self.window.rootViewController = qrCodeVCNav;
  103. // return;/*临时测试*/
  104. if(_isNeedToStopWork){
  105. return;
  106. }
  107. /*先判断本地有无设备 无设备时需要先扫码添加设备*/
  108. NSDictionary *deviceDict = [HWDataManager getObjectWithKey:Const_Have_Add_Device];
  109. if (!deviceDict || ![[deviceDict allKeys] containsObject:Const_Have_Add_Device_SN]){
  110. //默认显示最近文件
  111. [HWDataManager setBoolWithKey:Const_last_file_show value:YES];
  112. /*扫码界面*/
  113. TipsQRCodeViewController *qrCodeVC = [[TipsQRCodeViewController alloc] init];
  114. BaseNavigationController *qrCodeVCNav = [[BaseNavigationController alloc] initWithRootViewController:qrCodeVC];
  115. self.window.rootViewController = qrCodeVCNav;
  116. _isQRCodeType = YES;
  117. return;
  118. }
  119. NSString *SNStr = deviceDict[@"Const_Have_Add_Device_SN"];
  120. // GuideViewController
  121. BOOL haveGuide = [HWDataManager getBoolWithKey:Const_Have_Show_Guide];
  122. if (haveGuide) {
  123. ;
  124. }else {
  125. GuideViewController *guiDeVC = [[GuideViewController alloc] init];
  126. guiDeVC.delegate = self;
  127. guiDeVC.sn = SNStr;
  128. self.window.rootViewController = guiDeVC;
  129. return;
  130. }
  131. //BOOL haveOpenMask = [HWDataManager getBoolWithKey:Const_Mask_View_Open];
  132. #ifdef developJSQ
  133. NSInteger maskModel = 1;// [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  134. #else
  135. NSInteger maskModel = [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  136. #endif
  137. //添加默认启动图片
  138. if(!_customLaunchV && maskModel == 0){
  139. _customLaunchV = [[customLaunchView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H)];
  140. [self.window addSubview:_customLaunchV];
  141. }
  142. if(maskModel == 0 && _isFirstOpenInLaunch){
  143. //20240612 产品觉得 启动页太快了 要停两秒
  144. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  145. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable)
  146. {
  147. [[iToast makeText:NSLocalizedString(@"phone_network_fail_Tips",nil)] show];
  148. customToastVew *toastview = [customToastVew makeText:NSLocalizedString(@"phone_network_fail_Tips",nil)];
  149. [toastview show];
  150. [self->_customLaunchV addSubview:toastview];
  151. return;
  152. }
  153. [self getDeviceMsgInMainVCWith:deviceDict];
  154. });
  155. _isFirstOpenInLaunch = NO;
  156. }
  157. else{
  158. //延时等网络状态
  159. if(_isFirstOpenInLaunch){
  160. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  161. [self getDeviceMsgInMainVCWith:deviceDict];
  162. });
  163. _isFirstOpenInLaunch = NO;
  164. }
  165. else{
  166. [self getDeviceMsgInMainVCWith:deviceDict];
  167. }
  168. }
  169. //[self showNetErrorAlertType2Fun];
  170. }
  171. - (void)getDeviceMsgInMainVCWith:(NSDictionary*)deviceDict
  172. {
  173. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable)
  174. {
  175. BOOL isPrivacyMode = [HWDataManager getBoolWithKey:Const_Have_Add_Device_Privacy_Mode];
  176. NSInteger maskModel = [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  177. if(!isPrivacyMode && maskModel == 0){
  178. return;
  179. }
  180. [self initMainTabbarFun];
  181. [self showCalculatorVC];
  182. return;
  183. }
  184. KWeakSelf
  185. //有设备了先去做链接准备 // 80bec9c5
  186. NSString *SNStr = deviceDict[@"Const_Have_Add_Device_SN"];
  187. NSString *sdnId = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.sdnId;
  188. if(SNStr && !sdnId){
  189. [[connectDeviceManager shareInstance] getThridMsgBySN:SNStr needReconnect:YES didNetEnd:^(NSInteger didSuc) {
  190. if(didSuc == 0){
  191. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  192. mainBlock(^{
  193. [weakSelf showNetErrorAlertFun];
  194. [weakSelf enterMainVCFromSceneSecondStepFun];
  195. });
  196. });
  197. }
  198. else if(didSuc == 2
  199. ||didSuc == 201
  200. ||didSuc == 202){
  201. [weakSelf gotoScanAginByThridMsgErrorFun:didSuc];
  202. }
  203. else{
  204. [weakSelf enterMainVCFromSceneSecondStepFun];
  205. }
  206. }];
  207. }
  208. else{
  209. [self enterMainVCFromSceneSecondStepFun];
  210. }
  211. }
  212. - (void)enterMainVCFromSceneSecondStepFun
  213. {
  214. //确保通过SN号拿到密码了
  215. //非扫码进入 进入到这里很可能还没联网拿到设备最新信息
  216. if(![connectDeviceManager shareInstance].DeviceThirdIdMod){
  217. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  218. mainBlock(^{
  219. [self enterMainVCFromScene];
  220. });
  221. });
  222. return;
  223. }
  224. //是否已经有密码了 有就是输入密码 没有就是设置密码
  225. NSString *curPwd = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.password;
  226. NSString * sdnId = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.sdnId;
  227. if(!sdnId){
  228. HLog(@"没有拿到sdnId");
  229. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  230. mainBlock(^{
  231. [self enterMainVCFromScene];
  232. });
  233. });
  234. return;
  235. }
  236. if(_customLaunchV){
  237. [_customLaunchV removeFromSuperview];
  238. _customLaunchV = nil;
  239. }
  240. if(curPwd && curPwd.length > 0){
  241. /*设置密码*/
  242. // inputPWDViewController *nextVC = [[inputPWDViewController alloc] init];
  243. // BaseNavigationController *nextVCNav = [[BaseNavigationController alloc] initWithRootViewController:nextVC];
  244. // self.window.rootViewController = nextVCNav;
  245. }
  246. else{
  247. /*没有设置密码*/
  248. SetPWDFirstViewController *qrCodeVC = [[SetPWDFirstViewController alloc] init];
  249. BaseNavigationController *qrCodeVCNav = [[BaseNavigationController alloc] initWithRootViewController:qrCodeVC];
  250. self.window.rootViewController = qrCodeVCNav;
  251. return;
  252. }
  253. //下载配置先处理
  254. [boxDownloadFileManager shareInstance];
  255. [lastFileManager shareManager].uid = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.sn;
  256. [audioPlayListManager shareManager].uid = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.sn;
  257. //获取NAS相关信息
  258. [self getNASMsgFun];
  259. [self initMainTabbarFun];
  260. self.isLoginAgainType = NO;
  261. __block BOOL isPrivacyMode = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.isPrivacyMode;
  262. //KWeakSelf
  263. if(!_isQRCodeType){
  264. if(isPrivacyMode)
  265. {
  266. [self showCalculatorVC];
  267. }
  268. else{
  269. [self HandleEnterNotPrivacyModeFun];
  270. [connectDeviceManager shareInstance].isFirstInputPwdDone = YES;
  271. //playerRootVC.isPwdVCShow = NO;
  272. //[playerRootVC setShowImgAndVoiceTypeFun:YES];
  273. //[weakSelf shareAwakenAppBy:weakSelf.getShareStr];
  274. if(self->_session && self->_connectionOptions){
  275. [self scene:self->_session openURLContexts:self->_connectionOptions.URLContexts];
  276. }
  277. }
  278. //_isQRCodeType = NO;
  279. }
  280. else{
  281. if(isPrivacyMode)
  282. {
  283. [self showCalculatorVC];
  284. }
  285. else{
  286. }
  287. }
  288. _isQRCodeType = NO;
  289. //数据埋点
  290. [[netWorkManager shareInstance] DataEmbeddingPointBy:1 withEventValue:@"Nas"];
  291. return;
  292. // if(_curPlayerVC){
  293. // //[_curPlayerVC disconnectVideoServer];
  294. //
  295. // _curPlayerVC.isNeedRecyclResource = YES;
  296. // [_curPlayerVC recyclResource];
  297. //
  298. // _curPlayerVC.liveStreamManager = nil;
  299. // [_curPlayerVC.navigationController popViewControllerAnimated:NO];
  300. // _curPlayerVC = nil;
  301. // }
  302. //
  303. // //每次进入
  304. // PlayerViewController *playerRootVC = [[PlayerViewController alloc] init];
  305. // if(self.isLoginAgainType){
  306. // playerRootVC.isLoginAgainType = self.isLoginAgainType;
  307. // }
  308. // playerRootVC.isPwdVCShow = YES;
  309. // _curPlayerVC = playerRootVC;
  310. //
  311. //// BaseNavigationController *playerNav = [[BaseNavigationController alloc] initWithRootViewController:playerRootVC];
  312. //// self.window.rootViewController = playerNav;
  313. //
  314. // UIViewController *vc = [UIViewController new];
  315. //
  316. // BaseNavigationController *playerNav = [[BaseNavigationController alloc] initWithRootViewController:vc];
  317. // [playerNav pushViewController:playerRootVC animated:NO];
  318. // self.window.rootViewController = playerNav;
  319. //
  320. // _preRootPlayerNav = playerNav;
  321. //
  322. // self.isLoginAgainType = NO;
  323. //
  324. // __block BOOL isPrivacyMode = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.isPrivacyMode;
  325. //
  326. // KWeakSelf
  327. // if(!_isQRCodeType){
  328. //
  329. // if(isPrivacyMode)
  330. // {
  331. // [playerRootVC setShowImgAndVoiceTypeFun:NO];
  332. // [self showCalculatorVC];
  333. // }
  334. // else{
  335. // [self HandleEnterNotPrivacyModeFun];
  336. //
  337. // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  338. // mainBlock(^{
  339. // [connectDeviceManager shareInstance].isFirstInputPwdDone = YES;
  340. // playerRootVC.isPwdVCShow = NO;
  341. // [playerRootVC setShowImgAndVoiceTypeFun:YES];
  342. // //[weakSelf shareAwakenAppBy:weakSelf.getShareStr];
  343. //
  344. // if(self->_session && self->_connectionOptions){
  345. // [self scene:self->_session openURLContexts:self->_connectionOptions.URLContexts];
  346. // }
  347. // });
  348. // });
  349. // }
  350. //
  351. // //_isQRCodeType = NO;
  352. // }
  353. // else{
  354. // if(isPrivacyMode)
  355. // {
  356. // [playerRootVC setShowImgAndVoiceTypeFun:NO];
  357. // [self showCalculatorVC];
  358. // }
  359. // else{
  360. // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  361. // mainBlock(^{
  362. // playerRootVC.isPwdVCShow = NO;
  363. // [playerRootVC setShowImgAndVoiceTypeFun:YES];
  364. // });
  365. // });
  366. // }
  367. //
  368. // }
  369. //
  370. // _isQRCodeType = NO;
  371. //
  372. // //获取NAS相关信息
  373. // [self getNASMsgFun];
  374. //
  375. // [self initMainTabbarFun];
  376. }
  377. #pragma mark 1.4.1 新增tabbar
  378. - (void)initMainTabbarFun
  379. {
  380. UITabBarController *tabBarController = [[UITabBarController alloc] init];
  381. tabBarController.delegate = self;
  382. NASViewController *NASVC = [[NASViewController alloc] init];
  383. BaseNavigationController *NasNav = [[BaseNavigationController alloc] initWithRootViewController:NASVC];
  384. cloudPhoneViewController *cloudVC = [[cloudPhoneViewController alloc] init];
  385. BaseNavigationController *cloudPhoneNav = [[BaseNavigationController alloc] initWithRootViewController:cloudVC];
  386. mineViewController *mineVC = [[mineViewController alloc] init];
  387. BaseNavigationController *mineNav = [[BaseNavigationController alloc] initWithRootViewController:mineVC];
  388. NSArray *viewControllers = @[NasNav, cloudPhoneNav,mineNav]; // 添加更多视图控制器
  389. tabBarController.viewControllers = viewControllers;
  390. NSString*phoneTitle = NSLocalizedString(@"tabbar_cloud_phone",nil);
  391. NSString*myTitle = NSLocalizedString(@"tabbar_my_title",nil);
  392. NSArray *titleArr = @[@"NAS",phoneTitle,myTitle];
  393. NSArray *imageNArr = @[@"tabbar_nas_N", @"tabbar_phone_N",@"tabbar_my_N"];
  394. NSArray *imageHArr = @[@"tabbar_nas_H", @"tabbar_phone_H",@"tabbar_my_H"];
  395. for (int i=0; i<viewControllers.count; i++) {
  396. UITabBarItem * tabBarItem = [UITabBarItem new];
  397. tabBarItem.title = titleArr[i];
  398. tabBarItem.selectedImage = [[UIImage imageNamed:imageHArr[i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  399. tabBarItem.image = [[UIImage imageNamed:imageNArr[i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  400. UIViewController *curVC = viewControllers[i];
  401. curVC.tabBarItem = tabBarItem;
  402. }
  403. // tabBarController.tabBar.barTintColor = [UIColor hwColor:@"#F6F8FA"]; // 设置标签栏背景色
  404. // tabBarController.tabBar.tintColor = [UIColor hwColor:@"#01B7EA"]; // 设置选中标签项的颜色
  405. tabBarController.tabBar.backgroundColor = [UIColor whiteColor];
  406. [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor hwColor:@"#F6F8FA"],NSForegroundColorAttributeName, [UIFont systemFontOfSize:12.0],NSFontAttributeName,nil] forState:UIControlStateNormal];
  407. [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor hwColor:@"#01B7EA"],NSForegroundColorAttributeName, [UIFont systemFontOfSize:12.0],NSFontAttributeName,nil] forState:UIControlStateSelected];
  408. ksharedAppDelegate.mainTabBar = tabBarController;
  409. self.window.rootViewController = tabBarController;
  410. [self.window makeKeyAndVisible];
  411. }
  412. #pragma mark 处理进来是非隐私模式的情况
  413. - (void)HandleEnterNotPrivacyModeFun
  414. {
  415. #ifdef developJSQ
  416. NSInteger maskModel = 1;// [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  417. #else
  418. NSInteger maskModel = [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  419. #endif
  420. if (maskModel != 0){
  421. [HWDataManager setIntegerWithKey:Const_Mask_View_Model value:0];
  422. [iTools lc_setAlternateIconName:@"AppIcon1"];
  423. }
  424. }
  425. - (void)setPwdOk{
  426. [self enterMainVCFromScene];
  427. // NSArray *dataArray = [BaseModel bg_findAll:DB_BrowserWindows_TableName];
  428. //
  429. // if (dataArray.count == 0) { // 浏览器没有窗口
  430. // // 加载首页
  431. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  432. // vc.webUrl = Const_HomeUrl;
  433. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  434. // self.window.rootViewController = nvc;
  435. //
  436. // }else {
  437. // // 浏览器当前窗口索引ID
  438. // NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  439. // NSString *where = [NSString stringWithFormat:@"where %@=%ld",bg_sqlKey(@"ID"),(long)ID];
  440. // NSArray* finfAlls = [BaseModel bg_find:DB_BrowserWindows_TableName where:where];
  441. // BaseModel *model = finfAlls.firstObject;
  442. //
  443. // // 加载网页
  444. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  445. // vc.webUrl = model.webUrl;
  446. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  447. // self.window.rootViewController = nvc;
  448. // }
  449. }
  450. /** 登录界面 - 外部使用*/
  451. + (void)enterLoginVC {
  452. // SetPWDViewController *vc = [[SetPWDViewController alloc] init];
  453. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  454. // UIWindow *keyWindow = [iTools getKeyWindow];
  455. // keyWindow.rootViewController = nvc;
  456. }
  457. /** 主界面 - 外部使用 */
  458. + (void)enterMainVC {
  459. // AlbumHomeViewController *vc = [[AlbumHomeViewController alloc] init];
  460. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  461. // UIWindow *keyWindow = [iTools getKeyWindow];
  462. // keyWindow.rootViewController = nvc;
  463. }
  464. - (void)sceneDidDisconnect:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  465. HLog(@"sceneDidDisconnect");
  466. //[[boxDownloadFileManager shareInstance] suspendDownloadFileFun:YES withModel:nil withItem:nil];
  467. [[connectDeviceManager shareInstance] disconnect];
  468. }
  469. - (void)sceneDidBecomeActive:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  470. //控制2秒内回到前台不显示密码界面
  471. long seconds = [iTools getNowTimeStampSS];
  472. if(_preEnterBackgroundTime > 0){
  473. if(seconds - _preEnterBackgroundTime <= 2000){
  474. return;
  475. }
  476. }
  477. BOOL haveGuide = [HWDataManager getBoolWithKey:Const_Have_Show_Guide];
  478. if (haveGuide) {
  479. ;
  480. }else {
  481. return;
  482. }
  483. [self showCalculatorVC];
  484. }
  485. - (void)sceneWillResignActive:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  486. _preEnterBackgroundTime = [iTools getNowTimeStampSS];
  487. // BOOL haveGuide = [HWDataManager getBoolWithKey:Const_Have_Show_Guide];
  488. // if (haveGuide) {
  489. // ;
  490. // }else {
  491. //
  492. // return;
  493. // }
  494. // [self showCalculatorVC];
  495. }
  496. - (void)sceneWillEnterForeground:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  497. }
  498. - (void)sceneDidEnterBackground:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  499. // BOOL haveGuide = [HWDataManager getBoolWithKey:Const_Have_Show_Guide];
  500. // if (haveGuide) {
  501. // ;
  502. // }else {
  503. //
  504. // return;
  505. // }
  506. // [self showCalculatorVC];
  507. }
  508. - (void)scene:(UIScene *)scene continueUserActivity:(NSUserActivity *)userActivity {
  509. if([TencentOAuth CanHandleUniversalLink:userActivity.webpageURL]){
  510. [TencentOAuth HandleUniversalLink:userActivity.webpageURL];
  511. }
  512. else{
  513. [WXApi handleOpenUniversalLink:userActivity delegate:self];
  514. }
  515. }
  516. - (void)scene:(UIScene *)scene openURLContexts:(NSSet<UIOpenURLContext *> *)URLContexts {
  517. NSEnumerator *enumerator = [URLContexts objectEnumerator];
  518. UIOpenURLContext *context;
  519. while (context = [enumerator nextObject]) {
  520. NSLog(@"context.URL =====%@",context.URL);
  521. //openprivacyxapp://page?param1=value1&param2=value2
  522. NSString *curStr = context.URL.absoluteString;
  523. if([curStr rangeOfString:@"openprivacyxapp://page"].location != NSNotFound){
  524. _getShareStr = curStr;
  525. [self delayedHandlShareAwakenAppBy:curStr];
  526. break;
  527. }
  528. else{
  529. [WXApi handleOpenURL:context.URL delegate:self];
  530. }
  531. //NSLog(@"context.options.sourceApplication ===== %@",context.options.sourceApplication);
  532. }
  533. _session = nil;
  534. _connectionOptions = nil;
  535. }
  536. - (void)delayedHandlShareAwakenAppBy:(NSString*)curStr{
  537. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  538. [self shareAwakenAppBy:curStr];
  539. });
  540. }
  541. #pragma mark 初始化数据库-DB_BrowserWindows_TableName
  542. - (void)initBrowserWindow {
  543. // 浏览器当前所有窗口
  544. NSArray *dataArray = [BaseModel bg_findAll:DB_BrowserWindows_TableName];
  545. // 浏览器当前窗口索引ID
  546. NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  547. NSString *IDValue = [NSString stringWithFormat:@"%ld", ID];
  548. NSString *where = [NSString stringWithFormat:@"where %@=%@",bg_sqlKey(@"ID"),bg_sqlValue(IDValue)];
  549. NSArray *modelArr = [BaseModel bg_find:DB_BrowserWindows_TableName where:where];
  550. if (dataArray.count == 0) { // 浏览器没有窗口
  551. BaseModel *model = [[BaseModel alloc] init];
  552. model.ID = 0;
  553. model.name = @"主页";
  554. // model.iconFile = imageUrl;
  555. model.webUrl = Const_HomeUrl;
  556. // 写入数据库
  557. model.bg_tableName = DB_BrowserWindows_TableName;
  558. [model bg_saveOrUpdateAsync:^(BOOL isSuccess) {
  559. HLog(@"BaseModel写入:%@", isSuccess ? @"成功":@"失败");
  560. }];
  561. // 浏览器当前窗口索引ID
  562. [HWDataManager setIntegerWithKey:BrowserWindowsCurrentID value:0];
  563. }else if (modelArr.count == 0) { // 新建窗口
  564. BaseModel *model = [[BaseModel alloc] init];
  565. model.ID = ID;
  566. model.name = @"主页";
  567. // model.iconFile = imageUrl;
  568. model.webUrl = Const_HomeUrl;
  569. // 写入数据库
  570. model.bg_tableName = DB_BrowserWindows_TableName;
  571. [model bg_saveOrUpdateAsync:^(BOOL isSuccess) {
  572. HLog(@"BaseModel写入:%@", isSuccess ? @"成功":@"失败");
  573. }];
  574. }else { // 更新窗口数据
  575. // 浏览器当前窗口索引ID
  576. // NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  577. //
  578. // BaseModel *model = [[BaseModel alloc] init];
  579. // model.ID = ID;
  580. // model.name = @"主页";
  581. //// model.iconFile = imageUrl;
  582. // model.webUrl = Const_HomeUrl;
  583. //
  584. // // 更新数据库
  585. // model.bg_tableName = DB_BrowserWindows_TableName;
  586. // [model bg_saveOrUpdateAsync:^(BOOL isSuccess) {
  587. // HLog(@"BaseModel更新: %@", isSuccess ? @"成功":@"失败");
  588. // }];
  589. }
  590. }
  591. #pragma mark 获取当前屏幕的截图
  592. //- (UIImage *)getScreenShotImage {
  593. // CGSize size = [UIScreen mainScreen].bounds.size;
  594. // CGFloat scale = [UIScreen mainScreen].scale;
  595. // UIGraphicsBeginImageContextWithOptions(size, YES, scale);
  596. // [self.window.layer renderInContext:UIGraphicsGetCurrentContext()];
  597. // UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
  598. // UIGraphicsEndImageContext();
  599. // return image;
  600. //}
  601. #pragma mark 计算器伪装视图
  602. /*CalculatorViewController*/
  603. - (void)showCalculatorVC{
  604. if(ksharedAppDelegate.getSystemPermissType){
  605. HLog(@"检测到获取系统全进入后台");
  606. return;
  607. }
  608. BOOL isPrivacyMode = [HWDataManager getBoolWithKey:Const_Have_Add_Device_Privacy_Mode];
  609. if(!isPrivacyMode){
  610. return;
  611. }
  612. //修复扫描已经有密码的合作 点击跳过因为网络弹框再次覆盖一次密码(需要输入两次密码)
  613. BaseNavigationController*curTopNav = (BaseNavigationController*)[iTools appRootViewController];
  614. if([curTopNav isKindOfClass:[BaseNavigationController class]]){
  615. NSArray *vcArr = [curTopNav viewControllers];
  616. if(vcArr && vcArr.count >0){
  617. UIViewController *lastVC = vcArr.lastObject;
  618. if([lastVC isKindOfClass:[inputPWDViewController class]]){
  619. return;
  620. }
  621. }
  622. }
  623. /*无有效时长直接返回不加载任何加密界面*/
  624. NSString *PwdStr = nil;
  625. NSDictionary *deviceDict = [HWDataManager getObjectWithKey:Const_Have_Add_Device];
  626. //实时拿到的密码 (每次打开或者更换设备 通过SN重新拿)
  627. if([connectDeviceManager shareInstance].DeviceThirdIdMod.data.password){
  628. NSString *curPwd = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.password;
  629. NSString*desPwdStr = [RSATool AES128Decrypt:curPwd key:AESCODEKEEYY];
  630. if(desPwdStr){
  631. PwdStr = desPwdStr;
  632. }
  633. }
  634. else{
  635. //本地密码本地判断 密码改在服务器保持
  636. if ([[deviceDict allKeys] containsObject:Const_Have_Add_Device_PWD]){
  637. PwdStr = [deviceDict objectForKey:Const_Have_Add_Device_PWD];
  638. }
  639. }
  640. if (!PwdStr || [PwdStr isEqualToString:@""])
  641. {
  642. return;
  643. }
  644. // BOOL haveOpenMask = [HWDataManager getBoolWithKey:Const_Mask_View_Open];
  645. // if (!haveOpenMask){
  646. // //输入密码界面
  647. // [self closeCalculatorVC];
  648. // _inputVC = [[inputPWDViewController alloc] init];
  649. // [self.window addSubview:_inputVC.view];
  650. // return;
  651. // }
  652. BOOL haveVaildTime = [HWDataManager getBoolWithKey:Const_Have_No_VaildTime];
  653. if (haveVaildTime == YES){/*无有效时间*/
  654. return;
  655. }
  656. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus != AFNetworkReachabilityStatusNotReachable)
  657. {
  658. if(![connectDeviceManager shareInstance].DeviceThirdIdMod){
  659. return;
  660. }
  661. BOOL isPrivacyMode = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.isPrivacyMode;
  662. if(!isPrivacyMode)
  663. {
  664. [connectDeviceManager shareInstance].isFirstInputPwdDone = YES;
  665. [[NSNotificationCenter defaultCenter] postNotificationName:didInputPWDNotification object:nil];
  666. return;
  667. }
  668. }
  669. #ifdef developJSQ
  670. NSInteger maskModel = 1;// [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  671. #else
  672. NSInteger maskModel = [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  673. #endif
  674. if (maskModel == 0){
  675. //输入密码界面
  676. [self closeCalculatorVC];
  677. _inputVC = [[inputPWDViewController alloc] init];
  678. [self.window addSubview:_inputVC.view];
  679. _isDidShowPwdType = YES;
  680. }
  681. else if (maskModel == 2){
  682. /*浏览器*/
  683. [self closeCalculatorVC];
  684. _webVC = [[HWWebViewController alloc] init];
  685. _webVC.pwd = PwdStr;
  686. _webVC.webUrl = @"https://baidu.com";
  687. [self.window addSubview:_webVC.view];
  688. _isDidShowPwdType = YES;
  689. }else{
  690. /*计算器*/
  691. [self closeCalculatorVC];
  692. _calculatorVC = [[CalculatorViewController alloc] init];
  693. _calculatorVC.pwd = PwdStr;
  694. [self.window addSubview:_calculatorVC.view];
  695. _isDidShowPwdType = YES;
  696. }
  697. [[NSNotificationCenter defaultCenter] postNotificationName:ShowPwdVCNotification object:nil];
  698. }
  699. - (void)closeCalculatorVC{
  700. ksharedAppDelegate.getSystemPermissType = NO;
  701. if (_calculatorVC){
  702. [_calculatorVC.view removeFromSuperview];
  703. }
  704. /*浏览器*/
  705. if (_webVC){
  706. [_webVC.view removeFromSuperview];
  707. }
  708. if(_inputVC){
  709. [_inputVC.view removeFromSuperview];
  710. }
  711. _isDidShowPwdType = NO;
  712. if(self->_session && self->_connectionOptions){
  713. [self scene:self->_session openURLContexts:self->_connectionOptions.URLContexts];
  714. }
  715. }
  716. - (NSString *)documentPathForAccount:(NSString *)account fileFolder:(NSString *)fileFolder {
  717. NSString *path = DocumentPath;
  718. if (account.length != 0) {
  719. path = [NSString stringWithFormat:@"%@/%@/",DocumentPath,account];
  720. }
  721. if ([fileFolder containsString:@"/"]) {
  722. NSString *path1 = [path stringByAppendingPathComponent:fileFolder];
  723. path1 = [path1 stringByDeletingLastPathComponent];
  724. NSError *error;
  725. if (![[NSFileManager defaultManager] fileExistsAtPath:path1]) {
  726. [[NSFileManager defaultManager] createDirectoryAtPath:path1 withIntermediateDirectories:YES attributes:nil error:&error];
  727. }
  728. }else{
  729. NSError *error;
  730. if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
  731. [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error];
  732. }
  733. }
  734. return [path stringByAppendingPathComponent:fileFolder];
  735. }
  736. - (void)startUseBtnBePressed{
  737. [self enterMainVCFromScene];
  738. // NSString *launchAppPWDPath = [self documentPathForAccount:@"" fileFolder:@"LaunchPWD"];
  739. // NSString *str = [[NSString alloc] initWithContentsOfFile:launchAppPWDPath encoding:(NSUTF8StringEncoding) error:nil];
  740. // if (!str || [str isEqualToString:@"0"])
  741. // {
  742. // SetUsePWDViewController *loginVC = [[SetUsePWDViewController alloc] init];
  743. // loginVC.delegate = self;
  744. // self.window.rootViewController = loginVC;
  745. //
  746. // return;
  747. // }
  748. //
  749. // NSArray *dataArray = [BaseModel bg_findAll:DB_BrowserWindows_TableName];
  750. //
  751. // if (dataArray.count == 0) { // 浏览器没有窗口
  752. // // 加载首页
  753. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  754. // vc.webUrl = Const_HomeUrl;
  755. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  756. // self.window.rootViewController = nvc;
  757. //
  758. // }else {
  759. // // 浏览器当前窗口索引ID
  760. // NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  761. // NSString *where = [NSString stringWithFormat:@"where %@=%ld",bg_sqlKey(@"ID"),(long)ID];
  762. // NSArray* finfAlls = [BaseModel bg_find:DB_BrowserWindows_TableName where:where];
  763. // BaseModel *model = finfAlls.firstObject;
  764. //
  765. // // 加载网页
  766. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  767. // vc.webUrl = model.webUrl;
  768. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  769. // self.window.rootViewController = nvc;
  770. // }
  771. }
  772. - (void)loginOk{
  773. [self enterMainVCFromScene];
  774. }
  775. - (void)guideOk:(NSNotification*)not{
  776. NSString *object = not.object;
  777. if(object && [object isEqualToString:@"isLoginAgainType"]){
  778. self.isLoginAgainType = YES;
  779. }
  780. [self enterMainVCFromScene];
  781. //clear下载和上传的已经获取的数据
  782. [[uploadFileManager shareInstance] suspendUploadFileFun:YES withModel:nil];
  783. [uploadFileManager shareInstance].databaseArr = [NSMutableArray new];
  784. [uploadFileManager shareInstance].fileModelDataArr = [NSMutableArray new];
  785. [uploadFileManager shareInstance].curUploadFileDataModel.curUploadStateType = uploadStateWait;
  786. [[downloadManager shareInstance] suspendDownloadFileFun:YES withModel:nil];
  787. [downloadManager shareInstance].databaseArr = [NSMutableArray new];
  788. [downloadManager shareInstance].downLoadFileModelDataArr = [NSMutableArray new];
  789. [[backupsFileManager shareInstance] suspendBackupsFileFun];
  790. //frp的下载
  791. [[customDownloadManager shareManager] suspendAllDownloadTask];
  792. NSString *uid =[connectDeviceManager shareInstance].DeviceThirdIdMod.data.sn;
  793. if(uid){
  794. }
  795. else{
  796. uid = @"";
  797. }
  798. [customDownloadManager shareManager].uid = uid;
  799. //盒子1音频在播放音乐,切换盒子2成功,仍在播放中
  800. [[DFPlayer sharedPlayer] df_deallocPlayer];
  801. [lastFileManager shareManager].uid = uid;
  802. [audioPlayListManager shareManager].uid = uid;
  803. }
  804. #pragma mark 上报版本号信息
  805. -(void)reportVersionInfoFun
  806. {
  807. NSMutableDictionary *paraDict = [NSMutableDictionary new];
  808. NSString *vers = [iPhone appVersion];
  809. if(vers){
  810. [paraDict setValue:vers forKey:@"iosClientVersionNumber"];
  811. }
  812. NSDictionary *deviceDict = [HWDataManager getObjectWithKey:Const_Have_Add_Device];
  813. if (deviceDict && [[deviceDict allKeys] containsObject:Const_Have_Add_Device_SN]){
  814. NSString*snStr = deviceDict[Const_Have_Add_Device_SN];
  815. if(snStr){
  816. [paraDict setValue:snStr forKey:@"sn"];
  817. }
  818. else{
  819. return;
  820. }
  821. }
  822. else{
  823. return;;
  824. }
  825. // KWeakSelf
  826. [[netWorkManager shareInstance] CommonPostCallBackCode:reportVersionInfo Parameters:paraDict success:^(id _Nonnull responseObject) {
  827. } failure:^(NSError * _Nonnull error) {
  828. }];
  829. }
  830. #pragma mark 获取NAS相关信息
  831. -(void)getNASMsgFun
  832. {
  833. NSMutableDictionary *paraDict = [NSMutableDictionary new];
  834. NSString *SNStr = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.changeSn;
  835. if(SNStr){
  836. [paraDict setValue:SNStr forKey:@"sn"];
  837. }
  838. else{
  839. return;;
  840. }
  841. KWeakSelf
  842. [[netWorkManager shareInstance] CommonGetWithCallBackCode:getIpFun Parameters:paraDict success:^(id _Nonnull responseObject){
  843. NASMsgModel *model = [[NASMsgModel alloc] initWithDictionary:responseObject error:nil];
  844. if(model){
  845. ksharedAppDelegate.NASMsgMod = model;
  846. }
  847. } failure:^(NSError * _Nonnull error) {
  848. }];
  849. }
  850. #pragma mark 主动上锁
  851. - (void)showLockViewFun:(NSNotification*)not
  852. {
  853. [self showCalculatorVC];
  854. }
  855. #pragma mark 进入设置密码
  856. //- (void)setPwdVCFun:(NSNotification*)not
  857. //{
  858. // _isNeedToShowSecretKey = YES;
  859. //}
  860. #pragma mark 忘记密码
  861. - (void)forgetPwdFun:(NSNotification*)not
  862. {
  863. /*忘记密码*/
  864. forgetPwdViewController *forgetPwdVC = [[forgetPwdViewController alloc] init];
  865. BaseNavigationController *forgetPwdVCNav = [[BaseNavigationController alloc] initWithRootViewController:forgetPwdVC];
  866. self.window.rootViewController = forgetPwdVCNav;
  867. }
  868. #pragma mark 忘记密码返回
  869. - (void)forgetPwdBackFun:(NSNotification*)not
  870. {
  871. // if(_preRootPlayerNav)
  872. // {
  873. // self.window.rootViewController = _preRootPlayerNav;
  874. // }
  875. // else{
  876. [self enterMainVCFromScene];
  877. //}
  878. [self showCalculatorVC];
  879. }
  880. #pragma mark 忘记密码设置密码完成
  881. - (void)forgetPwdDidSetPwdFun:(NSNotification*)not
  882. {
  883. // if(_preRootPlayerNav)
  884. // {
  885. // NSArray *vcArr = _preRootPlayerNav.viewControllers;
  886. // if(vcArr.count > 2){
  887. // [_preRootPlayerNav popToViewController:vcArr[1] animated:NO];
  888. // }
  889. // self.window.rootViewController = _preRootPlayerNav;
  890. // }
  891. // else{
  892. [self enterMainVCFromScene];
  893. //}
  894. [self closeCalculatorVC];
  895. _curPlayerVC.isPwdVCShow = NO;
  896. [_curPlayerVC setShowImgAndVoiceTypeFun:YES];
  897. [connectDeviceManager shareInstance].isFirstInputPwdDone = YES;
  898. }
  899. #pragma mark 扫码切换设备 scanChangeDeviceNotification
  900. - (void)scanChangeDeviceFun:(NSNotification*)not
  901. {
  902. //TipsQRCodeForChangeDeviceViewController *nextVC = [[TipsQRCodeForChangeDeviceViewController alloc] init];
  903. QRCodeScanForChangeDeviceViewController *nextVC = [[QRCodeScanForChangeDeviceViewController alloc] init];
  904. nextVC.isRootVCType = YES;
  905. BaseNavigationController *nextNav = [[BaseNavigationController alloc] initWithRootViewController:nextVC];
  906. self.window.rootViewController = nextNav;
  907. }
  908. #pragma mark 扫码切换设备点击返回
  909. - (void)scanChangeDeviceBackFun:(NSNotification*)not
  910. {
  911. // if(_preRootPlayerNav)
  912. // {
  913. // self.window.rootViewController = _preRootPlayerNav;
  914. // }
  915. // else{
  916. [self enterMainVCFromScene];
  917. //}
  918. [self showCalculatorVC];
  919. }
  920. #pragma mark 网络异常弹框
  921. -(void)showNetErrorAlertFun
  922. {
  923. NSInteger maskModel = [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  924. if(maskModel !=0 && _isDidShowPwdType){
  925. return;
  926. }
  927. NSString *linkErrTip = NSLocalizedString(@"player_link_fail_tip_type9",nil);
  928. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable){
  929. linkErrTip = NSLocalizedString(@"player_link_fail_phone_Tips",nil);
  930. _isNeedToStopWork = YES;
  931. [self showNetErrorAlertType2Fun];
  932. return;
  933. }
  934. linkErrTip = [[NSString alloc] initWithFormat:@"[9]%@",linkErrTip];
  935. ComontAlretViewController *linkFailAlretVC= [[ComontAlretViewController alloc] initWithTiTle:nil
  936. msg:linkErrTip
  937. imageStr:nil
  938. cancelTitle:NSLocalizedString(@"single_sign_on_exit",nil)
  939. okTitle:NSLocalizedString(@"player_link_fail_tryAgain",nil) isOkBtnHighlight:YES
  940. didClickOk:^{
  941. //[self enterMainVCFromScene];
  942. } didClickCancel:^{
  943. exit(0);
  944. }];
  945. linkFailAlretVC.modalPresentationStyle = UIModalPresentationCustom;
  946. [self.window.rootViewController presentViewController:linkFailAlretVC animated:YES completion:^{
  947. linkFailAlretVC.view.superview.backgroundColor = [UIColor clearColor];
  948. }];
  949. }
  950. #pragma mark 网络异常弹框
  951. -(void)showNetErrorAlertType2Fun
  952. {
  953. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable){
  954. NSString * linkErrTip = NSLocalizedString(@"netWork_error_tip_content",nil);
  955. ComontAlretViewController *linkFailAlretVC= [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"netWork_error_tip_title",nil)
  956. msg:linkErrTip
  957. imageStr:nil
  958. cancelTitle:NSLocalizedString(@"single_sign_on_exit",nil)
  959. okTitle:nil isOkBtnHighlight:NO
  960. didClickOk:^{
  961. //[self enterMainVCFromScene];
  962. } didClickCancel:^{
  963. exit(0);
  964. }];
  965. linkFailAlretVC.modalPresentationStyle = UIModalPresentationCustom;
  966. self.window.rootViewController = [UIViewController new];
  967. [self.window.rootViewController presentViewController:linkFailAlretVC animated:YES completion:^{
  968. linkFailAlretVC.view.superview.backgroundColor = [UIColor clearColor];
  969. }];
  970. }
  971. }
  972. - (void)gotoScanAginByThridMsgErrorFun:(NSInteger)errorCode
  973. {
  974. /*扫码界面*/
  975. TipsQRCodeViewController *qrCodeVC = [[TipsQRCodeViewController alloc] init];
  976. qrCodeVC.isNeedToShowAleatType = YES;
  977. qrCodeVC.getSNMsgcode = errorCode;
  978. BaseNavigationController *qrCodeVCNav = [[BaseNavigationController alloc] initWithRootViewController:qrCodeVC];
  979. self.window.rootViewController = qrCodeVCNav;
  980. }
  981. #pragma mark 分享页面唤醒APP
  982. - (void)shareAwakenAppBy:(NSString*)shareStr
  983. {
  984. //[[iToast makeText:shareStr] show];
  985. NSArray * paraArr = [shareStr componentsSeparatedByString:@"&"];
  986. if(!paraArr || paraArr.count==0){
  987. return;
  988. }
  989. //type=save和download
  990. NSString *type = nil;
  991. NSString *fileIds = nil;
  992. NSString *extractionCode = nil;
  993. NSString *token = nil;
  994. for (NSString*objectStr in paraArr) {
  995. if([objectStr rangeOfString:@"type"].location != NSNotFound){
  996. NSArray * objectArr = [objectStr componentsSeparatedByString:@"="];
  997. if(objectArr.count == 2){
  998. type = objectArr.lastObject;
  999. continue;
  1000. }
  1001. }
  1002. else if([objectStr rangeOfString:@"fileIds"].location != NSNotFound){
  1003. NSArray * objectArr = [objectStr componentsSeparatedByString:@"="];
  1004. if(objectArr.count == 2){
  1005. fileIds = objectArr.lastObject;
  1006. continue;
  1007. }
  1008. }
  1009. else if([objectStr rangeOfString:@"extractionCode"].location != NSNotFound){
  1010. NSArray * objectArr = [objectStr componentsSeparatedByString:@"="];
  1011. if(objectArr.count == 2){
  1012. extractionCode = objectArr.lastObject;
  1013. continue;
  1014. }
  1015. }
  1016. else if([objectStr rangeOfString:@"token"].location != NSNotFound){
  1017. NSArray * objectArr = [objectStr componentsSeparatedByString:@"="];
  1018. if(objectArr.count == 2){
  1019. token = objectArr.lastObject;
  1020. continue;
  1021. }
  1022. }
  1023. }
  1024. if(!type || type.length ==0){
  1025. HLog(@"分享 type 获取错误");
  1026. return;
  1027. }
  1028. if(!fileIds || fileIds.length ==0){
  1029. HLog(@"分享 fileIds 获取错误");
  1030. return;
  1031. }
  1032. if(!token || token.length ==0){
  1033. HLog(@"分享 token 获取错误");
  1034. return;
  1035. }
  1036. [self getShareOneFileListFunByToken:token withFileIds:fileIds withExtractionCode:extractionCode withType:type];
  1037. }
  1038. #pragma mark 分享信息重新获取
  1039. - (void)getShareOneFileListFunByToken:(NSString*)token withFileIds:(NSString*)fileIds withExtractionCode:(NSString*)extractionCode withType:(NSString*)type
  1040. {
  1041. NSMutableDictionary*paraDict = [NSMutableDictionary new];
  1042. fileIds = [fileIds stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  1043. NSData *jsonData = [fileIds dataUsingEncoding:NSUTF8StringEncoding];;
  1044. NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
  1045. HLog(@"jsonArray:%@",jsonArray)
  1046. if(!jsonArray){
  1047. return;
  1048. }
  1049. [paraDict setValue:token forKey:@"token"];
  1050. [paraDict setValue:jsonArray forKey:@"fileIdList"];
  1051. [paraDict setValue:extractionCode forKey:@"extractionCode"];
  1052. KWeakSelf
  1053. [[netWorkManager shareInstance] CommonPostCallBackCode:queryOneShareInfoFun Parameters:paraDict success:^(id _Nonnull responseObject) {
  1054. queryOneShareModel*model = [[queryOneShareModel alloc] initWithDictionary:responseObject error:nil];
  1055. if(model && model.status == 0){
  1056. weakSelf.getShareStr = nil;
  1057. [weakSelf gotoVCByModel:model withType:type];
  1058. }
  1059. else{
  1060. }
  1061. } failure:^(NSError * _Nonnull error) {
  1062. }];
  1063. }
  1064. #pragma mark 跳转
  1065. - (void)gotoVCByModel:(queryOneShareModel*)model withType:(NSString*)type
  1066. {
  1067. if([type isEqualToString:@"save"]){
  1068. [self saveFileToBoxFunBy:model];
  1069. //数据埋点
  1070. [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Share_save"];
  1071. }
  1072. else if([type isEqualToString:@"download"]){
  1073. [self downloadFileToAppFunBy:model];
  1074. //数据埋点
  1075. [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Share_download"];
  1076. }
  1077. }
  1078. #pragma mark 保存文件到盒子
  1079. - (void)saveFileToBoxFunBy:(queryOneShareModel*)sharemodel
  1080. {
  1081. NSMutableDictionary*paraDict = [NSMutableDictionary new];
  1082. NSMutableArray *pathArr = [NSMutableArray new];
  1083. for (ShareFileDataModel*dataModel in sharemodel.data.fileListVOS){
  1084. [pathArr addObject:dataModel.fileUrl];
  1085. }
  1086. if (pathArr) {
  1087. NSString *jsonStr = [iTools toJsonStrWithArray:pathArr];
  1088. if(jsonStr){
  1089. [paraDict setValue:jsonStr forKey:@"urls"];
  1090. }
  1091. }
  1092. NSString * boxSaveDefaultPath = [HWDataManager getStringWithKey:stringKeyAddSn(Const_box_save_default_path)];
  1093. if(!boxSaveDefaultPath || boxSaveDefaultPath.length == 0){
  1094. boxSaveDefaultPath = Const_default_save_path;
  1095. [HWDataManager setStringWithKey:stringKeyAddSn(Const_box_save_default_path) value:boxSaveDefaultPath];
  1096. }
  1097. [paraDict setValue:boxSaveDefaultPath forKey:@"savePath"];
  1098. KWeakSelf
  1099. [[netWorkManager shareInstance] cloudPhoneGETCallBackCode:@"downFiles" Parameters:paraDict success:^(id _Nonnull responseObject) {
  1100. SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
  1101. if(model && model.status == 0){
  1102. [weakSelf gotoUploadFileRecordVCFunByType:2 withModel:sharemodel];
  1103. }
  1104. } failure:^(NSError * _Nonnull error) {
  1105. }];
  1106. }
  1107. #pragma mark 下载文件到手机
  1108. - (void)downloadFileToAppFunBy:(queryOneShareModel*)sharemodel
  1109. {
  1110. [self gotoUploadFileRecordVCFunByType:1 withModel:sharemodel];
  1111. }
  1112. #pragma mark 跳转传输列表
  1113. - (void)gotoUploadFileRecordVCFunByType:(NSInteger)type withModel:(queryOneShareModel*)sharemodel
  1114. {
  1115. KWeakSelf
  1116. if(type == 2){
  1117. [[boxSaveFileManager shareInstance] addBoxSaveRecordFunBy:sharemodel.data.fileListVOS complete:^(BOOL isSuccess) {
  1118. if(isSuccess){
  1119. mainBlock(^{
  1120. [weakSelf gotoUploadFileRecordVCFunByType:type];
  1121. });
  1122. }
  1123. }];
  1124. }
  1125. else if (type == 1){
  1126. if(![iTools checkFreeDiskSpaceInBytesIsOK:500*1024*1024]){
  1127. mainBlock(^{
  1128. [[iToast makeText:NSLocalizedString(@"phone_space_Insufficient",nil)] show];
  1129. });
  1130. return;
  1131. }
  1132. [[boxDownloadFileManager shareInstance] addBoxDownloadRecordFunBy:sharemodel.data.fileListVOS complete:^(BOOL isSuccess) {
  1133. if(isSuccess){
  1134. mainBlock(^{
  1135. [weakSelf gotoUploadFileRecordVCFunByType:type];
  1136. });
  1137. }
  1138. }];
  1139. }
  1140. }
  1141. - (void)gotoUploadFileRecordVCFunByType:(NSInteger)type
  1142. {
  1143. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  1144. vc.isReceiveType = type;
  1145. BaseNavigationController*mainNav = ksharedAppDelegate.mainTabBar.selectedViewController;
  1146. if([mainNav isKindOfClass:[BaseNavigationController class]]){
  1147. [mainNav pushViewController:vc animated:YES];
  1148. [[UIApplication sharedApplication] setStatusBarHidden:NO];
  1149. }
  1150. }
  1151. #pragma mark UITabBarControllerDelegate
  1152. - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
  1153. {
  1154. NSInteger index = tabBarController.selectedIndex;
  1155. //HLog(@"hxd %ld",index);
  1156. int eventType = 1;
  1157. NSString* eventValue = @"Nas";
  1158. if(index == 0){
  1159. eventValue = @"Nas";
  1160. }
  1161. else if(index == 1){
  1162. eventValue = @"Cloud";
  1163. }
  1164. else if(index == 2){
  1165. eventValue = @"Home";
  1166. }
  1167. //数据埋点
  1168. [[netWorkManager shareInstance] DataEmbeddingPointBy:eventType withEventValue:eventValue];
  1169. }
  1170. @end