SceneDelegate.m 52 KB

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