SceneDelegate.m 51 KB

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