SceneDelegate.m 54 KB

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