SceneDelegate.m 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494
  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. ksharedAppDelegate.mainTabBar = tabBarController;
  403. self.window.rootViewController = tabBarController;
  404. [self.window makeKeyAndVisible];
  405. }
  406. #pragma mark 处理进来是非隐私模式的情况
  407. - (void)HandleEnterNotPrivacyModeFun
  408. {
  409. #ifdef developJSQ
  410. NSInteger maskModel = 1;// [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  411. #else
  412. NSInteger maskModel = [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  413. #endif
  414. if (maskModel != 0){
  415. [HWDataManager setIntegerWithKey:Const_Mask_View_Model value:0];
  416. [iTools lc_setAlternateIconName:@"AppIcon1"];
  417. }
  418. }
  419. - (void)setPwdOk{
  420. [self enterMainVCFromScene];
  421. // NSArray *dataArray = [BaseModel bg_findAll:DB_BrowserWindows_TableName];
  422. //
  423. // if (dataArray.count == 0) { // 浏览器没有窗口
  424. // // 加载首页
  425. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  426. // vc.webUrl = Const_HomeUrl;
  427. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  428. // self.window.rootViewController = nvc;
  429. //
  430. // }else {
  431. // // 浏览器当前窗口索引ID
  432. // NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  433. // NSString *where = [NSString stringWithFormat:@"where %@=%ld",bg_sqlKey(@"ID"),(long)ID];
  434. // NSArray* finfAlls = [BaseModel bg_find:DB_BrowserWindows_TableName where:where];
  435. // BaseModel *model = finfAlls.firstObject;
  436. //
  437. // // 加载网页
  438. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  439. // vc.webUrl = model.webUrl;
  440. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  441. // self.window.rootViewController = nvc;
  442. // }
  443. }
  444. /** 登录界面 - 外部使用*/
  445. + (void)enterLoginVC {
  446. // SetPWDViewController *vc = [[SetPWDViewController alloc] init];
  447. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  448. // UIWindow *keyWindow = [iTools getKeyWindow];
  449. // keyWindow.rootViewController = nvc;
  450. }
  451. /** 主界面 - 外部使用 */
  452. + (void)enterMainVC {
  453. // AlbumHomeViewController *vc = [[AlbumHomeViewController alloc] init];
  454. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  455. // UIWindow *keyWindow = [iTools getKeyWindow];
  456. // keyWindow.rootViewController = nvc;
  457. }
  458. - (void)sceneDidDisconnect:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  459. HLog(@"sceneDidDisconnect");
  460. //[[connectDeviceManager shareInstance] disconnect];
  461. }
  462. - (void)sceneDidBecomeActive:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  463. HLog(@"sceneDidBecomeActive")
  464. }
  465. - (void)sceneWillResignActive:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  466. HLog(@"sceneWillResignActive")
  467. }
  468. - (void)sceneWillEnterForeground:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  469. HLog(@"sceneWillEnterForeground")
  470. }
  471. - (void)sceneDidEnterBackground:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  472. HLog(@"sceneDidEnterBackground")
  473. BOOL isPrivacyMode = [HWDataManager getBoolWithKey:Const_Have_Add_Device_Privacy_Mode];
  474. if(ksharedAppDelegate.DeviceThirdIdMod){
  475. isPrivacyMode = ksharedAppDelegate.DeviceThirdIdMod.data.isPrivacyMode;
  476. }
  477. if(isPrivacyMode){//隐私模式 需要弹密码框 转竖屏
  478. BOOL isNeeddelayedType = NO;
  479. //这里强制竖屏 处理图片详情 和视频详情的横屏情况
  480. BaseNavigationController*mainNav = ksharedAppDelegate.mainTabBar.selectedViewController;
  481. if([mainNav isKindOfClass:[BaseNavigationController class]]){
  482. NSArray* vcArr = mainNav.viewControllers;
  483. if(vcArr.count >= 2){
  484. UIViewController *curVC = vcArr.lastObject;
  485. if([curVC isKindOfClass:[imageDetailsScrollViewController class]]
  486. ||[curVC isKindOfClass:[videoPlayByAVPlayerViewController class]]
  487. ||[curVC isKindOfClass:[webRtcPlayerViewController class]]){
  488. //切换到竖屏
  489. ksharedAppDelegate.supportScreenRotateType = YES;
  490. [curVC hx_rotateToInterfaceOrientation:UIInterfaceOrientationPortrait];
  491. //ksharedAppDelegate.supportScreenRotateType = NO;
  492. isNeeddelayedType = YES;
  493. HLog(@"sceneDidEnterBackground 旋转屏幕为竖屏")
  494. }
  495. }
  496. }
  497. }
  498. [self showCalculatorVC];
  499. // if(isNeeddelayedType){
  500. // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  501. // ksharedAppDelegate.supportScreenRotateType = NO;
  502. // [self showCalculatorVC];
  503. // });
  504. // }
  505. // else{
  506. // [self showCalculatorVC];
  507. // }
  508. }
  509. - (void)scene:(UIScene *)scene continueUserActivity:(NSUserActivity *)userActivity {
  510. HLog(@"scene continueUserActivity")
  511. if([TencentOAuth CanHandleUniversalLink:userActivity.webpageURL]){
  512. [TencentOAuth HandleUniversalLink:userActivity.webpageURL];
  513. }
  514. else{
  515. [WXApi handleOpenUniversalLink:userActivity delegate:self];
  516. }
  517. }
  518. - (void)scene:(UIScene *)scene openURLContexts:(NSSet<UIOpenURLContext *> *)URLContexts {
  519. HLog(@"scene openURLContexts")
  520. NSEnumerator *enumerator = [URLContexts objectEnumerator];
  521. UIOpenURLContext *context;
  522. while (context = [enumerator nextObject]) {
  523. NSLog(@"context.URL =====%@",context.URL);
  524. //openprivacyxapp://page?param1=value1&param2=value2
  525. NSString *curStr = context.URL.absoluteString;
  526. if([curStr rangeOfString:@"openprivacyxapp://page"].location != NSNotFound){
  527. _getShareStr = curStr;
  528. [self delayedHandlShareAwakenAppBy:curStr];
  529. break;
  530. }
  531. else{
  532. [WXApi handleOpenURL:context.URL delegate:self];
  533. }
  534. //NSLog(@"context.options.sourceApplication ===== %@",context.options.sourceApplication);
  535. }
  536. _session = nil;
  537. _connectionOptions = nil;
  538. }
  539. - (void)delayedHandlShareAwakenAppBy:(NSString*)curStr{
  540. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  541. [self shareAwakenAppBy:curStr];
  542. });
  543. }
  544. #pragma mark 初始化数据库-DB_BrowserWindows_TableName
  545. - (void)initBrowserWindow {
  546. // 浏览器当前所有窗口
  547. NSArray *dataArray = [BaseModel bg_findAll:DB_BrowserWindows_TableName];
  548. // 浏览器当前窗口索引ID
  549. NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  550. NSString *IDValue = [NSString stringWithFormat:@"%ld", ID];
  551. NSString *where = [NSString stringWithFormat:@"where %@=%@",bg_sqlKey(@"ID"),bg_sqlValue(IDValue)];
  552. NSArray *modelArr = [BaseModel bg_find:DB_BrowserWindows_TableName where:where];
  553. if (dataArray.count == 0) { // 浏览器没有窗口
  554. BaseModel *model = [[BaseModel alloc] init];
  555. model.ID = 0;
  556. model.name = @"主页";
  557. // model.iconFile = imageUrl;
  558. model.webUrl = Const_HomeUrl;
  559. // 写入数据库
  560. model.bg_tableName = DB_BrowserWindows_TableName;
  561. [model bg_saveOrUpdateAsync:^(BOOL isSuccess) {
  562. HLog(@"BaseModel写入:%@", isSuccess ? @"成功":@"失败");
  563. }];
  564. // 浏览器当前窗口索引ID
  565. [HWDataManager setIntegerWithKey:BrowserWindowsCurrentID value:0];
  566. }else if (modelArr.count == 0) { // 新建窗口
  567. BaseModel *model = [[BaseModel alloc] init];
  568. model.ID = ID;
  569. model.name = @"主页";
  570. // model.iconFile = imageUrl;
  571. model.webUrl = Const_HomeUrl;
  572. // 写入数据库
  573. model.bg_tableName = DB_BrowserWindows_TableName;
  574. [model bg_saveOrUpdateAsync:^(BOOL isSuccess) {
  575. HLog(@"BaseModel写入:%@", isSuccess ? @"成功":@"失败");
  576. }];
  577. }else { // 更新窗口数据
  578. // 浏览器当前窗口索引ID
  579. // NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  580. //
  581. // BaseModel *model = [[BaseModel alloc] init];
  582. // model.ID = ID;
  583. // model.name = @"主页";
  584. //// model.iconFile = imageUrl;
  585. // model.webUrl = Const_HomeUrl;
  586. //
  587. // // 更新数据库
  588. // model.bg_tableName = DB_BrowserWindows_TableName;
  589. // [model bg_saveOrUpdateAsync:^(BOOL isSuccess) {
  590. // HLog(@"BaseModel更新: %@", isSuccess ? @"成功":@"失败");
  591. // }];
  592. }
  593. }
  594. #pragma mark 获取当前屏幕的截图
  595. //- (UIImage *)getScreenShotImage {
  596. // CGSize size = [UIScreen mainScreen].bounds.size;
  597. // CGFloat scale = [UIScreen mainScreen].scale;
  598. // UIGraphicsBeginImageContextWithOptions(size, YES, scale);
  599. // [self.window.layer renderInContext:UIGraphicsGetCurrentContext()];
  600. // UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
  601. // UIGraphicsEndImageContext();
  602. // return image;
  603. //}
  604. #pragma mark 计算器伪装视图
  605. /*CalculatorViewController*/
  606. - (void)showCalculatorVC{
  607. HLog(@"showCalculatorVC 处理密码框弹出")
  608. if(SCREEN_W > SCREEN_H){
  609. HLog(@"showCalculatorVC 屏幕还是横屏状态")
  610. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  611. [self showCalculatorVC];
  612. });
  613. return;
  614. }
  615. ksharedAppDelegate.supportScreenRotateType = NO;
  616. if(ksharedAppDelegate.getSystemPermissType){
  617. HLog(@"检测到获取系统全进入后台");
  618. return;
  619. }
  620. BOOL haveGuide = [HWDataManager getBoolWithKey:Const_Have_Show_Guide];
  621. if (haveGuide) {
  622. ;
  623. }else {
  624. return;
  625. }
  626. BOOL isPrivacyMode = [HWDataManager getBoolWithKey:Const_Have_Add_Device_Privacy_Mode];
  627. if(ksharedAppDelegate.DeviceThirdIdMod){
  628. isPrivacyMode = ksharedAppDelegate.DeviceThirdIdMod.data.isPrivacyMode;
  629. }
  630. if(!isPrivacyMode){
  631. return;
  632. }
  633. //修复扫描已经有密码的合作 点击跳过因为网络弹框再次覆盖一次密码(需要输入两次密码)
  634. BaseNavigationController*curTopNav = (BaseNavigationController*)[iTools appRootViewController];
  635. if([curTopNav isKindOfClass:[BaseNavigationController class]]){
  636. NSArray *vcArr = [curTopNav viewControllers];
  637. if(vcArr && vcArr.count >0){
  638. UIViewController *lastVC = vcArr.lastObject;
  639. if([lastVC isKindOfClass:[inputPWDViewController class]]){
  640. return;
  641. }
  642. }
  643. }
  644. /*无有效时长直接返回不加载任何加密界面*/
  645. NSString *PwdStr = nil;
  646. NSDictionary *deviceDict = [HWDataManager getObjectWithKey:Const_Have_Add_Device];
  647. //实时拿到的密码 (每次打开或者更换设备 通过SN重新拿)
  648. if(ksharedAppDelegate.DeviceThirdIdMod.data.password){
  649. NSString *curPwd = ksharedAppDelegate.DeviceThirdIdMod.data.password;
  650. NSString*desPwdStr = [RSATool AES128Decrypt:curPwd key:AESCODEKEEYY];
  651. if(desPwdStr){
  652. PwdStr = desPwdStr;
  653. }
  654. }
  655. else{
  656. //本地密码本地判断 密码改在服务器保持
  657. if ([[deviceDict allKeys] containsObject:Const_Have_Add_Device_PWD]){
  658. PwdStr = [deviceDict objectForKey:Const_Have_Add_Device_PWD];
  659. }
  660. }
  661. if (!PwdStr || [PwdStr isEqualToString:@""])
  662. {
  663. return;
  664. }
  665. // BOOL haveOpenMask = [HWDataManager getBoolWithKey:Const_Mask_View_Open];
  666. // if (!haveOpenMask){
  667. // //输入密码界面
  668. // [self closeCalculatorVC];
  669. // _inputVC = [[inputPWDViewController alloc] init];
  670. // [self.window addSubview:_inputVC.view];
  671. // return;
  672. // }
  673. BOOL haveVaildTime = [HWDataManager getBoolWithKey:Const_Have_No_VaildTime];
  674. if (haveVaildTime == YES){/*无有效时间*/
  675. return;
  676. }
  677. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus != AFNetworkReachabilityStatusNotReachable)
  678. {
  679. if(!ksharedAppDelegate.DeviceThirdIdMod){
  680. return;
  681. }
  682. BOOL isPrivacyMode = ksharedAppDelegate.DeviceThirdIdMod.data.isPrivacyMode;
  683. if(!isPrivacyMode)
  684. {
  685. ksharedAppDelegate.isFirstInputPwdDone = YES;
  686. [[NSNotificationCenter defaultCenter] postNotificationName:didInputPWDNotification object:nil];
  687. return;
  688. }
  689. }
  690. #ifdef developJSQ
  691. NSInteger maskModel = 1;// [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  692. #else
  693. NSInteger maskModel = [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  694. #endif
  695. if (maskModel == 0){
  696. //输入密码界面
  697. [self closeCalculatorVC];
  698. _inputVC = [[inputPWDViewController alloc] init];
  699. [self.window addSubview:_inputVC.view];
  700. ksharedAppDelegate.isDidShowPwdType = YES;
  701. }
  702. else if (maskModel == 2){
  703. /*浏览器*/
  704. [self closeCalculatorVC];
  705. _webVC = [[HWWebViewController alloc] init];
  706. _webVC.pwd = PwdStr;
  707. _webVC.webUrl = @"https://baidu.com";
  708. [self.window addSubview:_webVC.view];
  709. ksharedAppDelegate.isDidShowPwdType = YES;
  710. }else{
  711. /*计算器*/
  712. [self closeCalculatorVC];
  713. _calculatorVC = [[CalculatorViewController alloc] init];
  714. _calculatorVC.pwd = PwdStr;
  715. [self.window addSubview:_calculatorVC.view];
  716. ksharedAppDelegate.isDidShowPwdType = YES;
  717. }
  718. [[NSNotificationCenter defaultCenter] postNotificationName:ShowPwdVCNotification object:nil];
  719. }
  720. - (void)closeCalculatorVC{
  721. ksharedAppDelegate.getSystemPermissType = NO;
  722. if (_calculatorVC){
  723. [_calculatorVC.view removeFromSuperview];
  724. }
  725. /*浏览器*/
  726. if (_webVC){
  727. [_webVC.view removeFromSuperview];
  728. }
  729. if(_inputVC){
  730. [_inputVC.view removeFromSuperview];
  731. }
  732. ksharedAppDelegate.isDidShowPwdType = NO;
  733. if(self->_session && self->_connectionOptions){
  734. [self scene:self->_session openURLContexts:self->_connectionOptions.URLContexts];
  735. }
  736. }
  737. - (NSString *)documentPathForAccount:(NSString *)account fileFolder:(NSString *)fileFolder {
  738. NSString *path = DocumentPath;
  739. if (account.length != 0) {
  740. path = [NSString stringWithFormat:@"%@/%@/",DocumentPath,account];
  741. }
  742. if ([fileFolder containsString:@"/"]) {
  743. NSString *path1 = [path stringByAppendingPathComponent:fileFolder];
  744. path1 = [path1 stringByDeletingLastPathComponent];
  745. NSError *error;
  746. if (![[NSFileManager defaultManager] fileExistsAtPath:path1]) {
  747. [[NSFileManager defaultManager] createDirectoryAtPath:path1 withIntermediateDirectories:YES attributes:nil error:&error];
  748. }
  749. }else{
  750. NSError *error;
  751. if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
  752. [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error];
  753. }
  754. }
  755. return [path stringByAppendingPathComponent:fileFolder];
  756. }
  757. - (void)startUseBtnBePressed{
  758. [self enterMainVCFromScene];
  759. // NSString *launchAppPWDPath = [self documentPathForAccount:@"" fileFolder:@"LaunchPWD"];
  760. // NSString *str = [[NSString alloc] initWithContentsOfFile:launchAppPWDPath encoding:(NSUTF8StringEncoding) error:nil];
  761. // if (!str || [str isEqualToString:@"0"])
  762. // {
  763. // SetUsePWDViewController *loginVC = [[SetUsePWDViewController alloc] init];
  764. // loginVC.delegate = self;
  765. // self.window.rootViewController = loginVC;
  766. //
  767. // return;
  768. // }
  769. //
  770. // NSArray *dataArray = [BaseModel bg_findAll:DB_BrowserWindows_TableName];
  771. //
  772. // if (dataArray.count == 0) { // 浏览器没有窗口
  773. // // 加载首页
  774. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  775. // vc.webUrl = Const_HomeUrl;
  776. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  777. // self.window.rootViewController = nvc;
  778. //
  779. // }else {
  780. // // 浏览器当前窗口索引ID
  781. // NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  782. // NSString *where = [NSString stringWithFormat:@"where %@=%ld",bg_sqlKey(@"ID"),(long)ID];
  783. // NSArray* finfAlls = [BaseModel bg_find:DB_BrowserWindows_TableName where:where];
  784. // BaseModel *model = finfAlls.firstObject;
  785. //
  786. // // 加载网页
  787. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  788. // vc.webUrl = model.webUrl;
  789. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  790. // self.window.rootViewController = nvc;
  791. // }
  792. }
  793. - (void)loginOk{
  794. [self enterMainVCFromScene];
  795. }
  796. - (void)guideOk:(NSNotification*)not{
  797. NSString *object = not.object;
  798. if(object && [object isEqualToString:@"isLoginAgainType"]){
  799. self.isLoginAgainType = YES;
  800. }
  801. //clear下载和上传的已经获取的数据
  802. // [[uploadFileManager shareInstance] suspendUploadFileFun:YES withModel:nil];
  803. // [uploadFileManager shareInstance].databaseArr = [NSMutableArray new];
  804. // [uploadFileManager shareInstance].fileModelDataArr = [NSMutableArray new];
  805. // [uploadFileManager shareInstance].curUploadFileDataModel.curUploadStateType = uploadStateWait;
  806. [[nasUploadFileManager shareInstance] suspendUploadFileFun:YES withModel:nil];
  807. [nasUploadFileManager shareInstance].databaseArr = nil;
  808. // [[downloadManager shareInstance] suspendDownloadFileFun:YES withModel:nil];
  809. // [downloadManager shareInstance].databaseArr = [NSMutableArray new];
  810. // [downloadManager shareInstance].downLoadFileModelDataArr = [NSMutableArray new];
  811. [[nasDownloadFileManager shareInstance] suspendDownloadFileFun:YES withModel:nil];
  812. [nasDownloadFileManager shareInstance].databaseArr = nil;
  813. //[[backupsFileManager shareInstance] suspendBackupsFileFun];
  814. [[nasBackupsManager shareInstance] suspendBackupsFileFun];
  815. //frp的下载
  816. [[customDownloadManager shareManager] suspendAllDownloadTask];
  817. NSString *uid =ksharedAppDelegate.DeviceThirdIdMod.data.sn;
  818. if(uid){
  819. }
  820. else{
  821. uid = @"";
  822. }
  823. [customDownloadManager shareManager].uid = uid;
  824. //盒子1音频在播放音乐,切换盒子2成功,仍在播放中
  825. [[DFPlayer sharedPlayer] df_deallocPlayer];
  826. [lastFileManager shareManager].uid = uid;
  827. [audioPlayListManager shareManager].uid = uid;
  828. [self enterMainVCFromScene];
  829. }
  830. #pragma mark 上报版本号信息
  831. -(void)reportVersionInfoFun
  832. {
  833. NSMutableDictionary *paraDict = [NSMutableDictionary new];
  834. NSString *vers = [iPhone appVersion];
  835. if(vers){
  836. [paraDict setValue:vers forKey:@"iosClientVersionNumber"];
  837. }
  838. NSDictionary *deviceDict = [HWDataManager getObjectWithKey:Const_Have_Add_Device];
  839. if (deviceDict && [[deviceDict allKeys] containsObject:Const_Have_Add_Device_SN]){
  840. NSString*snStr = deviceDict[Const_Have_Add_Device_SN];
  841. if(snStr){
  842. [paraDict setValue:snStr forKey:@"sn"];
  843. }
  844. else{
  845. return;
  846. }
  847. }
  848. else{
  849. return;;
  850. }
  851. // KWeakSelf
  852. [[netWorkManager shareInstance] CommonPostCallBackCode:reportVersionInfo Parameters:paraDict success:^(id _Nonnull responseObject) {
  853. } failure:^(NSError * _Nonnull error) {
  854. }];
  855. }
  856. #pragma mark 获取NAS相关信息
  857. -(void)getNASMsgFun
  858. {
  859. NSMutableDictionary *paraDict = [NSMutableDictionary new];
  860. NSString *SNStr = ksharedAppDelegate.DeviceThirdIdMod.data.changeSn;
  861. if(SNStr){
  862. [paraDict setValue:SNStr forKey:@"sn"];
  863. }
  864. else{
  865. return;;
  866. }
  867. KWeakSelf
  868. [[netWorkManager shareInstance] CommonGetWithCallBackCode:getIpFun Parameters:paraDict success:^(id _Nonnull responseObject){
  869. NASMsgModel *model = [[NASMsgModel alloc] initWithDictionary:responseObject error:nil];
  870. if(model){
  871. ksharedAppDelegate.NASMsgMod = model;
  872. }
  873. } failure:^(NSError * _Nonnull error) {
  874. }];
  875. }
  876. #pragma mark 主动上锁
  877. - (void)showLockViewFun:(NSNotification*)not
  878. {
  879. [self showCalculatorVC];
  880. }
  881. #pragma mark 进入设置密码
  882. //- (void)setPwdVCFun:(NSNotification*)not
  883. //{
  884. // _isNeedToShowSecretKey = YES;
  885. //}
  886. #pragma mark 忘记密码
  887. - (void)forgetPwdFun:(NSNotification*)not
  888. {
  889. /*忘记密码*/
  890. forgetPwdViewController *forgetPwdVC = [[forgetPwdViewController alloc] init];
  891. BaseNavigationController *forgetPwdVCNav = [[BaseNavigationController alloc] initWithRootViewController:forgetPwdVC];
  892. self.window.rootViewController = forgetPwdVCNav;
  893. }
  894. #pragma mark 忘记密码返回
  895. - (void)forgetPwdBackFun:(NSNotification*)not
  896. {
  897. // if(_preRootPlayerNav)
  898. // {
  899. // self.window.rootViewController = _preRootPlayerNav;
  900. // }
  901. // else{
  902. [self enterMainVCFromScene];
  903. //}
  904. [self showCalculatorVC];
  905. }
  906. #pragma mark 忘记密码设置密码完成
  907. - (void)forgetPwdDidSetPwdFun:(NSNotification*)not
  908. {
  909. // if(_preRootPlayerNav)
  910. // {
  911. // NSArray *vcArr = _preRootPlayerNav.viewControllers;
  912. // if(vcArr.count > 2){
  913. // [_preRootPlayerNav popToViewController:vcArr[1] animated:NO];
  914. // }
  915. // self.window.rootViewController = _preRootPlayerNav;
  916. // }
  917. // else{
  918. [self enterMainVCFromScene];
  919. //}
  920. [self closeCalculatorVC];
  921. ksharedAppDelegate.isFirstInputPwdDone = YES;
  922. }
  923. #pragma mark 扫码切换设备 scanChangeDeviceNotification
  924. - (void)scanChangeDeviceFun:(NSNotification*)not
  925. {
  926. //TipsQRCodeForChangeDeviceViewController *nextVC = [[TipsQRCodeForChangeDeviceViewController alloc] init];
  927. QRCodeScanForChangeDeviceViewController *nextVC = [[QRCodeScanForChangeDeviceViewController alloc] init];
  928. nextVC.isRootVCType = YES;
  929. BaseNavigationController *nextNav = [[BaseNavigationController alloc] initWithRootViewController:nextVC];
  930. self.window.rootViewController = nextNav;
  931. }
  932. #pragma mark 扫码切换设备点击返回
  933. - (void)scanChangeDeviceBackFun:(NSNotification*)not
  934. {
  935. // if(_preRootPlayerNav)
  936. // {
  937. // self.window.rootViewController = _preRootPlayerNav;
  938. // }
  939. // else{
  940. [self enterMainVCFromScene];
  941. //}
  942. [self showCalculatorVC];
  943. }
  944. #pragma mark 网络异常弹框
  945. -(void)showNetErrorAlertFun
  946. {
  947. NSInteger maskModel = [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  948. if(maskModel !=0 && ksharedAppDelegate.isDidShowPwdType){
  949. return;
  950. }
  951. NSString *linkErrTip = NSLocalizedString(@"player_link_fail_tip_type9",nil);
  952. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable){
  953. //linkErrTip = NSLocalizedString(@"player_link_fail_phone_Tips",nil);
  954. _isNeedToStopWork = YES;
  955. [self showNetErrorAlertType2Fun];
  956. return;
  957. }
  958. linkErrTip = [[NSString alloc] initWithFormat:@"[9]%@",linkErrTip];
  959. ComontAlretViewController *linkFailAlretVC= [[ComontAlretViewController alloc] initWithTiTle:nil
  960. msg:linkErrTip
  961. imageStr:nil
  962. cancelTitle:NSLocalizedString(@"single_sign_on_exit",nil)
  963. okTitle:NSLocalizedString(@"player_link_fail_tryAgain",nil) isOkBtnHighlight:YES
  964. didClickOk:^{
  965. //[self enterMainVCFromScene];
  966. } didClickCancel:^{
  967. exit(0);
  968. }];
  969. linkFailAlretVC.modalPresentationStyle = UIModalPresentationCustom;
  970. [self.window.rootViewController presentViewController:linkFailAlretVC animated:YES completion:^{
  971. linkFailAlretVC.view.superview.backgroundColor = [UIColor clearColor];
  972. }];
  973. }
  974. #pragma mark 网络异常弹框
  975. -(void)showNetErrorAlertType2Fun
  976. {
  977. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable){
  978. NSString * linkErrTip = NSLocalizedString(@"netWork_error_tip_content",nil);
  979. ComontAlretViewController *linkFailAlretVC= [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"netWork_error_tip_title",nil)
  980. msg:linkErrTip
  981. imageStr:nil
  982. cancelTitle:NSLocalizedString(@"single_sign_on_exit",nil)
  983. okTitle:nil isOkBtnHighlight:NO
  984. didClickOk:^{
  985. //[self enterMainVCFromScene];
  986. } didClickCancel:^{
  987. exit(0);
  988. }];
  989. linkFailAlretVC.modalPresentationStyle = UIModalPresentationCustom;
  990. self.window.rootViewController = [UIViewController new];
  991. [self.window.rootViewController presentViewController:linkFailAlretVC animated:YES completion:^{
  992. linkFailAlretVC.view.superview.backgroundColor = [UIColor clearColor];
  993. }];
  994. }
  995. }
  996. - (void)gotoScanAginByThridMsgErrorFun:(NSInteger)errorCode
  997. {
  998. /*扫码界面*/
  999. TipsQRCodeViewController *qrCodeVC = [[TipsQRCodeViewController alloc] init];
  1000. qrCodeVC.isNeedToShowAleatType = YES;
  1001. qrCodeVC.getSNMsgcode = errorCode;
  1002. BaseNavigationController *qrCodeVCNav = [[BaseNavigationController alloc] initWithRootViewController:qrCodeVC];
  1003. self.window.rootViewController = qrCodeVCNav;
  1004. }
  1005. #pragma mark 分享页面唤醒APP
  1006. - (void)shareAwakenAppBy:(NSString*)shareStr
  1007. {
  1008. //[[iToast makeText:shareStr] show];
  1009. NSArray * paraArr = [shareStr componentsSeparatedByString:@"&"];
  1010. if(!paraArr || paraArr.count==0){
  1011. return;
  1012. }
  1013. //type=save和download
  1014. NSString *type = nil;
  1015. NSString *fileIds = nil;
  1016. NSString *extractionCode = nil;
  1017. NSString *token = nil;
  1018. for (NSString*objectStr in paraArr) {
  1019. if([objectStr rangeOfString:@"type"].location != NSNotFound){
  1020. NSArray * objectArr = [objectStr componentsSeparatedByString:@"="];
  1021. if(objectArr.count == 2){
  1022. type = objectArr.lastObject;
  1023. continue;
  1024. }
  1025. }
  1026. else if([objectStr rangeOfString:@"fileIds"].location != NSNotFound){
  1027. NSArray * objectArr = [objectStr componentsSeparatedByString:@"="];
  1028. if(objectArr.count == 2){
  1029. fileIds = objectArr.lastObject;
  1030. continue;
  1031. }
  1032. }
  1033. else if([objectStr rangeOfString:@"extractionCode"].location != NSNotFound){
  1034. NSArray * objectArr = [objectStr componentsSeparatedByString:@"="];
  1035. if(objectArr.count == 2){
  1036. extractionCode = objectArr.lastObject;
  1037. continue;
  1038. }
  1039. }
  1040. else if([objectStr rangeOfString:@"token"].location != NSNotFound){
  1041. NSArray * objectArr = [objectStr componentsSeparatedByString:@"="];
  1042. if(objectArr.count == 2){
  1043. token = objectArr.lastObject;
  1044. continue;
  1045. }
  1046. }
  1047. }
  1048. if(!type || type.length ==0){
  1049. HLog(@"分享 type 获取错误");
  1050. return;
  1051. }
  1052. if(!fileIds || fileIds.length ==0){
  1053. HLog(@"分享 fileIds 获取错误");
  1054. return;
  1055. }
  1056. if(!token || token.length ==0){
  1057. HLog(@"分享 token 获取错误");
  1058. return;
  1059. }
  1060. [self getShareOneFileListFunByToken:token withFileIds:fileIds withExtractionCode:extractionCode withType:type];
  1061. }
  1062. #pragma mark 分享信息重新获取
  1063. - (void)getShareOneFileListFunByToken:(NSString*)token withFileIds:(NSString*)fileIds withExtractionCode:(NSString*)extractionCode withType:(NSString*)type
  1064. {
  1065. NSMutableDictionary*paraDict = [NSMutableDictionary new];
  1066. fileIds = [fileIds stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  1067. NSData *jsonData = [fileIds dataUsingEncoding:NSUTF8StringEncoding];;
  1068. NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
  1069. HLog(@"jsonArray:%@",jsonArray)
  1070. if(!jsonArray){
  1071. return;
  1072. }
  1073. [paraDict setValue:token forKey:@"token"];
  1074. [paraDict setValue:jsonArray forKey:@"fileIdList"];
  1075. [paraDict setValue:extractionCode forKey:@"extractionCode"];
  1076. KWeakSelf
  1077. [[netWorkManager shareInstance] CommonPostCallBackCode:queryOneShareInfoFun Parameters:paraDict success:^(id _Nonnull responseObject) {
  1078. queryOneShareModel*model = [[queryOneShareModel alloc] initWithDictionary:responseObject error:nil];
  1079. if(model && model.status == 0){
  1080. weakSelf.getShareStr = nil;
  1081. [weakSelf gotoVCByModel:model withType:type];
  1082. }
  1083. else{
  1084. }
  1085. } failure:^(NSError * _Nonnull error) {
  1086. }];
  1087. }
  1088. #pragma mark 跳转
  1089. - (void)gotoVCByModel:(queryOneShareModel*)model withType:(NSString*)type
  1090. {
  1091. if([type isEqualToString:@"save"]){
  1092. [self saveFileToBoxFunBy:model];
  1093. //数据埋点
  1094. [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Share_save"];
  1095. }
  1096. else if([type isEqualToString:@"download"]){
  1097. [self downloadFileToAppFunBy:model];
  1098. //数据埋点
  1099. [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Share_download"];
  1100. }
  1101. }
  1102. #pragma mark 保存文件到盒子
  1103. - (void)saveFileToBoxFunBy:(queryOneShareModel*)sharemodel
  1104. {
  1105. NSMutableDictionary*paraDict = [NSMutableDictionary new];
  1106. NSMutableArray *pathArr = [NSMutableArray new];
  1107. for (ShareFileDataModel*dataModel in sharemodel.data.fileListVOS){
  1108. [pathArr addObject:dataModel.fileUrl];
  1109. }
  1110. if (pathArr) {
  1111. NSString *jsonStr = [iTools toJsonStrWithArray:pathArr];
  1112. if(jsonStr){
  1113. [paraDict setValue:jsonStr forKey:@"urls"];
  1114. }
  1115. }
  1116. NSString * boxSaveDefaultPath = [HWDataManager getStringWithKey:stringKeyAddSn(Const_box_save_default_path)];
  1117. if(!boxSaveDefaultPath || boxSaveDefaultPath.length == 0){
  1118. boxSaveDefaultPath = Const_default_save_path;
  1119. [HWDataManager setStringWithKey:stringKeyAddSn(Const_box_save_default_path) value:boxSaveDefaultPath];
  1120. }
  1121. [paraDict setValue:boxSaveDefaultPath forKey:@"savePath"];
  1122. KWeakSelf
  1123. [[netWorkManager shareInstance] cloudPhoneGETCallBackCode:@"downFiles" Parameters:paraDict success:^(id _Nonnull responseObject) {
  1124. SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
  1125. if(model && model.status == 0){
  1126. [weakSelf gotoUploadFileRecordVCFunByType:2 withModel:sharemodel];
  1127. }
  1128. } failure:^(NSError * _Nonnull error) {
  1129. }];
  1130. }
  1131. #pragma mark 下载文件到手机
  1132. - (void)downloadFileToAppFunBy:(queryOneShareModel*)sharemodel
  1133. {
  1134. [self gotoUploadFileRecordVCFunByType:1 withModel:sharemodel];
  1135. }
  1136. #pragma mark 跳转传输列表
  1137. - (void)gotoUploadFileRecordVCFunByType:(NSInteger)type withModel:(queryOneShareModel*)sharemodel
  1138. {
  1139. KWeakSelf
  1140. if(type == 2){
  1141. [[boxSaveFileManager shareInstance] addBoxSaveRecordFunBy:sharemodel.data.fileListVOS complete:^(BOOL isSuccess) {
  1142. if(isSuccess){
  1143. mainBlock(^{
  1144. [weakSelf gotoUploadFileRecordVCFunByType:type];
  1145. });
  1146. }
  1147. }];
  1148. }
  1149. else if (type == 1){
  1150. if(![iTools checkFreeDiskSpaceInBytesIsOK:500*1024*1024]){
  1151. mainBlock(^{
  1152. [[iToast makeText:NSLocalizedString(@"phone_space_Insufficient",nil)] show];
  1153. });
  1154. return;
  1155. }
  1156. [[boxDownloadFileManager shareInstance] addBoxDownloadRecordFunBy:sharemodel.data.fileListVOS complete:^(BOOL isSuccess) {
  1157. if(isSuccess){
  1158. mainBlock(^{
  1159. [weakSelf gotoUploadFileRecordVCFunByType:type];
  1160. });
  1161. }
  1162. }];
  1163. }
  1164. }
  1165. - (void)gotoUploadFileRecordVCFunByType:(NSInteger)type
  1166. {
  1167. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  1168. vc.isReceiveType = type;
  1169. BaseNavigationController*mainNav = ksharedAppDelegate.mainTabBar.selectedViewController;
  1170. if([mainNav isKindOfClass:[BaseNavigationController class]]){
  1171. [mainNav pushViewController:vc animated:YES];
  1172. [[UIApplication sharedApplication] setStatusBarHidden:NO];
  1173. }
  1174. }
  1175. #pragma mark UITabBarControllerDelegate
  1176. - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
  1177. {
  1178. NSInteger index = tabBarController.selectedIndex;
  1179. int eventType = 1;
  1180. NSString* eventValue = @"Nas";
  1181. if(index == 0){
  1182. eventValue = @"Nas";
  1183. }
  1184. else if(index == 1){
  1185. eventValue = @"Cloud";
  1186. }
  1187. else if(index == 2){
  1188. eventValue = @"Home";
  1189. }
  1190. //数据埋点
  1191. [[netWorkManager shareInstance] DataEmbeddingPointBy:eventType withEventValue:eventValue];
  1192. }
  1193. @end