SceneDelegate.m 54 KB

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