SceneDelegate.m 52 KB

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