SceneDelegate.m 54 KB

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