SceneDelegate.m 53 KB

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