SceneDelegate.m 54 KB

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