SceneDelegate.m 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010
  1. //
  2. // SceneDelegate.m
  3. // Private-X
  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 "SafeForKey.h"
  14. #import "TipsQRCodeViewController.h"
  15. #import "SetPWDFirstViewController.h"
  16. #import "connectDeviceManager.h"
  17. #import "inputPWDViewController.h"
  18. #import "customLaunchView.h"
  19. #import "RSATool.h"
  20. #import "forgetPwdViewController.h"
  21. #import "TipsQRCodeForChangeDeviceViewController.h"
  22. #import "AFNetworkReachabilityManager.h"
  23. #import "ComontAlretViewController.h"
  24. #import "uploadFileManager.h"
  25. //#import "downloadManager.h"
  26. #import "nasDownloadFileManager.h"
  27. //#import "backupsFileManager.h"
  28. #import "nasBackupsManager.h"
  29. #import "iPhone.h"
  30. #import <WXApi.h>
  31. #import <TencentOpenAPI/QQApiInterface.h>
  32. #import <TencentOpenAPI/TencentOAuth.h>
  33. #import "NASMsgModel.h"
  34. #import "queryOneShareModel.h"
  35. #import "boxSaveFileManager.h"
  36. #import "boxDownloadFileManager.h"
  37. #import "NASViewController.h"
  38. #import "cloudPhoneViewController.h"
  39. #import "mineViewController.h"
  40. #import "lastFileManager.h"
  41. #import "customDownloadManager.h"
  42. #import "audioPlayListManager.h"
  43. #import "QRCodeScanForChangeDeviceViewController.h"
  44. #import "customToastVew.h"
  45. #import "DFPlayer.h"
  46. #import "UIInterface+HXRotation.h"
  47. #import "imageDetailsScrollViewController.h"
  48. #import "videoPlayByAVPlayerViewController.h"
  49. #import "pingManager.h"
  50. #import "webRtcPlayerViewController.h"
  51. #import "webRtcPingManager.h"
  52. #import "imageVersionRenewTipView.h"
  53. #import "HWVersionModel.h"
  54. #import "HaveNewVersionView.h"
  55. #import "newerGuideView.h"
  56. #import "CustomerWebViewController.h"
  57. #import "noticeModel.h"
  58. #import "HaveNoticeView.h"
  59. #import "UpgradeInfoModel.h"
  60. #import "imageVersionUpdateDoneView.h"
  61. #import "imageVersionUpdateFailView.h"
  62. #import "privacyModeTipViewController.h"
  63. #import "LoginType1ViewController.h"
  64. #import "previewFileAndFolderViewController.h"
  65. @interface SceneDelegate ()<SetUsePWDViewControllerDelegate,GuideViewControllerDelegate,UITabBarControllerDelegate>
  66. {
  67. imageVersionRenewTipView * RenewTipView;
  68. imageVersionUpdateDoneView* imageVersionUpdateDoneV;
  69. imageVersionUpdateFailView* imageVersionUpdateFailV;
  70. }
  71. @property (nonatomic,strong)UpgradeInfoModel*otaUpgradeInfoModel;
  72. @property(nonatomic, strong) CalculatorViewController *calculatorVC;
  73. @property(nonatomic, strong) HWWebViewController *webVC;
  74. @property(nonatomic, strong) inputPWDViewController *inputVC;
  75. @property(nonatomic, strong) customLaunchView *customLaunchV;//
  76. @property(nonatomic, strong) BaseNavigationController *preRootPlayerNav;
  77. @property(nonatomic, assign) bool isQRCodeType;//第一次 扫码进来的
  78. //@property(nonatomic, assign) bool isNeedToShowSecretKey;//扫码进来的SN 没有密码 则需要显示秘钥
  79. @property (nonatomic, assign) BOOL isLoginAgainType;// 单点登录 点重新登录进来的
  80. @property (nonatomic, assign) BOOL isNeedToStopWork;// 无网络报错
  81. @property(nonatomic, copy) NSString *getShareStr;//拿到分享的字符串
  82. @property (nonatomic, assign) BOOL isFirstOpenInLaunch;//启动页停两秒
  83. //冷启动分享跳入用
  84. @property(nonatomic, strong) UISceneSession *session;
  85. @property(nonatomic, strong) UISceneConnectionOptions *connectionOptions;
  86. @end
  87. @implementation SceneDelegate
  88. - (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions API_AVAILABLE(ios(13.0)){
  89. HLog(@"willConnectToSession")
  90. if (scene) {
  91. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(guideOk:) name:GuideOkNotification object:nil];
  92. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showLockViewFun:) name:lockBypwdNotification object:nil];
  93. //[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setPwdVCFun:) name:setPwdNotification object:nil];
  94. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(forgetPwdFun:) name:forgetPwdNotification object:nil];
  95. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(forgetPwdBackFun:) name:forgetPwdBackNotification object:nil];
  96. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(forgetPwdDidSetPwdFun:) name:forgetPwdDidSetNotification object:nil];
  97. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scanChangeDeviceFun:) name:scanChangeDeviceNotification object:nil];
  98. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scanChangeDeviceBackFun:) name:scanChangeDeviceBackNotification object:nil];
  99. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(firstDidLinkBoxFun) name:@"firstDidLinkBox" object:nil];
  100. UIWindowScene *windowScene = (UIWindowScene *)scene;
  101. self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
  102. self.window.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
  103. _isFirstOpenInLaunch = YES;
  104. // 初始化数据库
  105. [self initBrowserWindow];
  106. //查询当前的最近webrtc机房
  107. NSDictionary *dict = [HWDataManager getObjectWithKey:@"Const_best_webRtc_IPRoom"];
  108. if(dict){
  109. webrtcServerModel *model = [[webrtcServerModel alloc] initWithDictionary:dict error:nil];
  110. if(model && model.turnIp){
  111. ksharedAppDelegate.bestWebrtcServerModel = model;
  112. }
  113. }
  114. // 加载主页面
  115. [self enterMainVCFromScene];
  116. //
  117. [self reportVersionInfoFun];
  118. [self.window makeKeyAndVisible];
  119. ksharedAppDelegate.window = self.window;
  120. //冷启动
  121. if(connectionOptions.URLContexts != nil){
  122. _session = session;
  123. _connectionOptions = connectionOptions;
  124. // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  125. // mainBlock(^{
  126. // [self scene:scene openURLContexts:connectionOptions.URLContexts];
  127. // });
  128. // });
  129. }
  130. }
  131. }
  132. /** 主界面 - 内部使用 */
  133. - (void)enterMainVCFromScene {
  134. // ConnectTestViewController *qrCodeVCNav = [[ConnectTestViewController alloc] init];
  135. // self.window.rootViewController = qrCodeVCNav;
  136. // return;/*临时测试*/
  137. if(_isNeedToStopWork){
  138. return;
  139. }
  140. /*先判断本地有无设备 无设备时需要先扫码添加设备*/
  141. NSDictionary *deviceDict = [HWDataManager getObjectWithKey:Const_Have_Add_Device];
  142. if (!deviceDict || ![[deviceDict allKeys] containsObject:Const_Have_Add_Device_SN]){
  143. //默认显示最近文件
  144. [HWDataManager setBoolWithKey:Const_last_file_show value:YES];
  145. /*扫码界面*/
  146. //TipsQRCodeViewController *qrCodeVC = [[TipsQRCodeViewController alloc] init];
  147. LoginType1ViewController *qrCodeVC = [[LoginType1ViewController alloc] init];
  148. BaseNavigationController *qrCodeVCNav = [[BaseNavigationController alloc] initWithRootViewController:qrCodeVC];
  149. self.window.rootViewController = qrCodeVCNav;
  150. _isQRCodeType = YES;
  151. return;
  152. }
  153. NSString *SNStr = deviceDict[@"Const_Have_Add_Device_SN"];
  154. // GuideViewController
  155. BOOL haveGuide = [HWDataManager getBoolWithKey:Const_Have_Show_Guide];
  156. if (haveGuide) {
  157. ;
  158. }else {
  159. GuideViewController *guiDeVC = [[GuideViewController alloc] init];
  160. guiDeVC.delegate = self;
  161. guiDeVC.sn = SNStr;
  162. self.window.rootViewController = guiDeVC;
  163. return;
  164. }
  165. //BOOL haveOpenMask = [HWDataManager getBoolWithKey:Const_Mask_View_Open];
  166. #ifdef developJSQ
  167. NSInteger maskModel = 1;// [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  168. #else
  169. NSInteger maskModel = [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  170. #endif
  171. //添加默认启动图片
  172. if(!_customLaunchV && maskModel == 0){
  173. _customLaunchV = [[customLaunchView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H)];
  174. [self.window addSubview:_customLaunchV];
  175. }
  176. if(maskModel == 0 && _isFirstOpenInLaunch){
  177. //20240612 产品觉得 启动页太快了 要停两秒
  178. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  179. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable)
  180. {
  181. [[iToast makeText:NSLocalizedString(@"phone_network_fail_Tips",nil)] show];
  182. customToastVew *toastview = [customToastVew makeText:NSLocalizedString(@"phone_network_fail_Tips",nil)];
  183. [toastview show];
  184. [self->_customLaunchV addSubview:toastview];
  185. //return;
  186. }
  187. [self getDeviceMsgInMainVCWith:deviceDict];
  188. });
  189. _isFirstOpenInLaunch = NO;
  190. }
  191. else{
  192. //延时等网络状态
  193. if(_isFirstOpenInLaunch){
  194. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  195. [self getDeviceMsgInMainVCWith:deviceDict];
  196. });
  197. _isFirstOpenInLaunch = NO;
  198. }
  199. else{
  200. [self getDeviceMsgInMainVCWith:deviceDict];
  201. }
  202. }
  203. //[self showNetErrorAlertType2Fun];
  204. }
  205. - (void)getDeviceMsgInMainVCWith:(NSDictionary*)deviceDict
  206. {
  207. //有设备了先去做链接准备 // 80bec9c5
  208. NSString *SNStr = deviceDict[@"Const_Have_Add_Device_SN"];
  209. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable)
  210. {
  211. NSString *key = [[NSString alloc] initWithFormat:@"%@_%@",@"ThirdIdBySn",SNStr];
  212. NSDictionary*preResponseObject = [HWDataManager getObjectWithKey:key];
  213. if(preResponseObject){
  214. DeviceThirdIdModel *model = [[DeviceThirdIdModel alloc] initWithDictionary:preResponseObject error:nil];
  215. ksharedAppDelegate.DeviceThirdIdMod = model;
  216. [lastFileManager shareManager].uid = ksharedAppDelegate.DeviceThirdIdMod.data.sn;
  217. [audioPlayListManager shareManager].uid = ksharedAppDelegate.DeviceThirdIdMod.data.sn;
  218. }
  219. BOOL isPrivacyMode = [HWDataManager getBoolWithKey:Const_Have_Add_Device_Privacy_Mode];
  220. NSInteger maskModel = [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  221. if(!isPrivacyMode && maskModel == 0){
  222. //return;
  223. }
  224. [self initMainTabbarFun];
  225. [self showCalculatorVC];
  226. return;
  227. }
  228. KWeakSelf
  229. NSString *sdnId = ksharedAppDelegate.DeviceThirdIdMod.data.sdnId;
  230. if(SNStr && !sdnId){
  231. //webrtc方案
  232. NSMutableDictionary *paraDict = [NSMutableDictionary new];
  233. [paraDict setValue:SNStr forKey:@"sn"];
  234. KWeakSelf
  235. [[netWorkManager shareInstance] CommonGetWithCallBackCode:getThirdIdBySn Parameters:paraDict success:^(id _Nonnull responseObject) {
  236. DeviceThirdIdModel *model = [[DeviceThirdIdModel alloc] initWithDictionary:responseObject error:nil];
  237. if(model.status == 0
  238. && model.data)
  239. {//根据SN 获取到正确的信息
  240. ksharedAppDelegate.DeviceThirdIdMod = model;
  241. NSMutableDictionary *IdDataDict = [[NSMutableDictionary alloc] initWithDictionary:responseObject];
  242. for (NSString *key in responseObject) {
  243. id object = IdDataDict[key];
  244. if(!object || [object isKindOfClass:[NSNull class]]){
  245. [IdDataDict removeObjectForKey:key];
  246. }
  247. }
  248. if([[IdDataDict allKeys] containsObject:@"data"]){
  249. NSMutableDictionary *DataDict = [[NSMutableDictionary alloc] initWithDictionary:responseObject[@"data"]];
  250. for (NSString *key in responseObject[@"data"]) {
  251. id object = DataDict[key];
  252. if(!object || [object isKindOfClass:[NSNull class]]){
  253. [DataDict removeObjectForKey:key];
  254. }
  255. }
  256. IdDataDict[@"data"] = DataDict;
  257. }
  258. //数据缓存
  259. NSString *key = stringKeyAddSn(@"ThirdIdBySn");
  260. [HWDataManager setObjectWithKey:key value:IdDataDict];
  261. NSString*desPwdstr = [RSATool AES128Decrypt:model.data.password key:AESCODEKEEYY];
  262. /*密码保持在本地*/
  263. NSDictionary *deviceDict = [HWDataManager getObjectWithKey:Const_Have_Add_Device];
  264. NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithDictionary:deviceDict];
  265. [dict setObject:desPwdstr forKey:Const_Have_Add_Device_PWD];
  266. NSString *sdnid = model.data.sdnId;
  267. if(sdnid){
  268. [dict setObject:sdnid forKey:Const_Have_Add_Device_sdnid];
  269. }
  270. [HWDataManager setObjectWithKey:Const_Have_Add_Device_Privacy_Mode value:[NSNumber numberWithBool:model.data.isPrivacyMode]];
  271. [HWDataManager setObjectWithKey:Const_Have_Add_Device value:dict];
  272. [weakSelf enterMainVCFromSceneSecondStepFun];;
  273. //ping看上是否为内网情况
  274. [[pingManager shareManager] startPingDeviceIpFun];
  275. //获取webrtc相关信息
  276. [weakSelf queryWebRtcMsgFun];
  277. }
  278. else{
  279. //if(model.status == 201||model.status == 202 || model.status ==2){}
  280. [weakSelf gotoScanAginByThridMsgErrorFun:model.status];
  281. }
  282. } failure:^(NSError * _Nonnull error) {
  283. HLog("网络报错");
  284. mainBlock(^{
  285. [weakSelf showNetErrorAlertFun];
  286. [weakSelf enterMainVCFromSceneSecondStepFun];
  287. });
  288. }];
  289. }
  290. else{
  291. //ping看上是否为内网情况
  292. [[pingManager shareManager] startPingDeviceIpFun];
  293. if (!ksharedAppDelegate.DeviceWebRtcMsgMod) {
  294. //获取webrtc相关信息
  295. [weakSelf queryWebRtcMsgFun];
  296. }
  297. [self enterMainVCFromSceneSecondStepFun];
  298. }
  299. }
  300. #pragma mark 获取webrct 的链接信息
  301. -(void)queryWebRtcMsgFun
  302. {
  303. NSMutableDictionary *paraDict = [NSMutableDictionary new];
  304. KWeakSelf
  305. [[netWorkManager shareInstance] CommonPostCallBackCode:webrctQueryByClient Parameters:paraDict success:^(id _Nonnull responseObject){
  306. webRtcMsgModel *curModel = [[webRtcMsgModel alloc] initWithDictionary:responseObject error:nil];
  307. if(curModel && curModel.status == 0){
  308. ksharedAppDelegate.DeviceWebRtcMsgMod = curModel;
  309. if(!ksharedAppDelegate.bestWebrtcServerModel){
  310. webrtcServerModel *model = curModel.data.webrtcServerList.firstObject;
  311. ksharedAppDelegate.bestWebrtcServerModel = model;
  312. }
  313. [[webRtcManager shareManager] beginToLinkWebRtcFun];
  314. [[webRtcPingManager shareManager] startPingFun];
  315. }
  316. else
  317. {
  318. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  319. [weakSelf queryWebRtcMsgFun];
  320. });
  321. }
  322. } failure:^(NSError * _Nonnull error) {
  323. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  324. [weakSelf queryWebRtcMsgFun];
  325. });
  326. }];
  327. }
  328. - (void)enterMainVCFromSceneSecondStepFun
  329. {
  330. //确保通过SN号拿到密码了
  331. //非扫码进入 进入到这里很可能还没联网拿到设备最新信息
  332. if(!ksharedAppDelegate.DeviceThirdIdMod
  333. &&!ksharedAppDelegate.DeviceWebRtcMsgMod){
  334. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  335. mainBlock(^{
  336. [self enterMainVCFromScene];
  337. });
  338. });
  339. return;
  340. }
  341. //是否已经有密码了 有就是输入密码 没有就是设置密码
  342. NSString *curPwd = ksharedAppDelegate.DeviceThirdIdMod.data.password;
  343. NSString * sdnId = ksharedAppDelegate.DeviceThirdIdMod.data.sdnId;
  344. if(!sdnId && !ksharedAppDelegate.DeviceWebRtcMsgMod){
  345. HLog(@"没有拿到 --sdnId:%@ --- DeviceWebRtcMsgMod:%@",sdnId,ksharedAppDelegate.DeviceWebRtcMsgMod);
  346. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  347. mainBlock(^{
  348. [self enterMainVCFromScene];
  349. });
  350. });
  351. return;
  352. }
  353. if(_customLaunchV){
  354. [_customLaunchV removeFromSuperview];
  355. _customLaunchV = nil;
  356. }
  357. if(curPwd && curPwd.length > 0){
  358. /*设置密码*/
  359. // inputPWDViewController *nextVC = [[inputPWDViewController alloc] init];
  360. // BaseNavigationController *nextVCNav = [[BaseNavigationController alloc] initWithRootViewController:nextVC];
  361. // self.window.rootViewController = nextVCNav;
  362. }
  363. else{
  364. //1、重启、恢复出厂设备、首次设置密码 3个情况下8分钟之内不弹
  365. long seconds = [iTools getNowTimeStamp];
  366. NSNumber *secondsNum = [NSNumber numberWithLong:seconds];
  367. if(secondsNum){
  368. [HWDataManager setNumberWithKey:stringKeyAddSn(@"disenable_type2_BoxHeartbeat") value:secondsNum];
  369. }
  370. /*没有设置密码*/
  371. SetPWDFirstViewController *qrCodeVC = [[SetPWDFirstViewController alloc] init];
  372. BaseNavigationController *qrCodeVCNav = [[BaseNavigationController alloc] initWithRootViewController:qrCodeVC];
  373. self.window.rootViewController = qrCodeVCNav;
  374. return;
  375. }
  376. //下载配置先处理
  377. [boxDownloadFileManager shareInstance];
  378. [lastFileManager shareManager].uid = ksharedAppDelegate.DeviceThirdIdMod.data.sn;
  379. [audioPlayListManager shareManager].uid = ksharedAppDelegate.DeviceThirdIdMod.data.sn;
  380. //获取NAS相关信息
  381. [self getNASMsgFun];
  382. [self initMainTabbarFun];
  383. self.isLoginAgainType = NO;
  384. __block BOOL isPrivacyMode = ksharedAppDelegate.DeviceThirdIdMod.data.isPrivacyMode;
  385. //KWeakSelf
  386. if(!_isQRCodeType){
  387. if(isPrivacyMode)
  388. {
  389. [self showCalculatorVC];
  390. }
  391. else{
  392. [self HandleEnterNotPrivacyModeFun];
  393. ksharedAppDelegate.isFirstInputPwdDone = YES;
  394. //playerRootVC.isPwdVCShow = NO;
  395. //[playerRootVC setShowImgAndVoiceTypeFun:YES];
  396. //[weakSelf shareAwakenAppBy:weakSelf.getShareStr];
  397. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  398. [[NSNotificationCenter defaultCenter] postNotificationName:didInputPWDNotification object:nil];
  399. });
  400. if(self->_session && self->_connectionOptions){
  401. [self scene:self->_session openURLContexts:self->_connectionOptions.URLContexts];
  402. }
  403. }
  404. //_isQRCodeType = NO;
  405. }
  406. else{
  407. if(isPrivacyMode)
  408. {
  409. [self showCalculatorVC];
  410. }
  411. else{
  412. [[webRtcManager shareManager] beginToLinkWebRtcFun];
  413. ksharedAppDelegate.isFirstInputPwdDone = YES;
  414. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  415. [[NSNotificationCenter defaultCenter] postNotificationName:didInputPWDNotification object:nil];
  416. });
  417. }
  418. }
  419. _isQRCodeType = NO;
  420. //数据埋点
  421. [[netWorkManager shareInstance] DataEmbeddingPointBy:1 withEventValue:@"Nas"];
  422. }
  423. #pragma mark 1.4.1 新增tabbar
  424. - (void)initMainTabbarFun
  425. {
  426. UITabBarController *tabBarController = [[UITabBarController alloc] init];
  427. tabBarController.delegate = self;
  428. NASViewController *NASVC = [[NASViewController alloc] init];
  429. BaseNavigationController *NasNav = [[BaseNavigationController alloc] initWithRootViewController:NASVC];
  430. cloudPhoneViewController *cloudVC = [[cloudPhoneViewController alloc] init];
  431. BaseNavigationController *cloudPhoneNav = [[BaseNavigationController alloc] initWithRootViewController:cloudVC];
  432. previewFileAndFolderViewController *fileVC = [[previewFileAndFolderViewController alloc] init];
  433. BaseNavigationController *fileNav = [[BaseNavigationController alloc] initWithRootViewController:fileVC];
  434. mineViewController *mineVC = [[mineViewController alloc] init];
  435. BaseNavigationController *mineNav = [[BaseNavigationController alloc] initWithRootViewController:mineVC];
  436. NSString*phoneTitle = NSLocalizedString(@"tabbar_cloud_phone",nil);
  437. NSString*myTitle = NSLocalizedString(@"tabbar_my_title",nil);
  438. NSString*fileTitle = NSLocalizedString(@"my_set_no_file",nil);
  439. //NSArray *viewControllers = @[NasNav, cloudPhoneNav,mineNav]; // 添加更多视图控制器
  440. NSArray *viewControllers = @[NasNav,fileNav,mineNav]; // 添加更多视图控制器
  441. NSArray *titleArr = @[@"NAS",fileTitle,myTitle];
  442. NSArray *imageNArr = @[@"tabbar_nas_N", @"tabbar_file_N",@"tabbar_my_N"];
  443. NSArray *imageHArr = @[@"tabbar_nas_H", @"tabbar_file_H",@"tabbar_my_H"];
  444. //记录当前连接的SN
  445. NSString* preSN = [HWDataManager getStringWithKey:Const_pre_did_link_ok_sn];
  446. NSString *curSN = ksharedAppDelegate.DeviceThirdIdMod.data.changeSn;
  447. if(![curSN isEqualToString:@"0333933700223110016962"]
  448. && ![preSN isEqualToString:@"0333933700223110016962"]
  449. && preSN.length > 0){
  450. titleArr = @[@"NAS",phoneTitle,myTitle];
  451. imageNArr = @[@"tabbar_nas_N", @"my_device_NO",@"tabbar_my_N"];
  452. imageHArr = @[@"tabbar_nas_H", @"my_device_ok",@"tabbar_my_H"];
  453. viewControllers = @[NasNav,cloudPhoneNav,mineNav];
  454. }
  455. tabBarController.viewControllers = viewControllers;
  456. for (int i=0; i<viewControllers.count; i++) {
  457. UITabBarItem * tabBarItem = [UITabBarItem new];
  458. tabBarItem.title = titleArr[i];
  459. tabBarItem.selectedImage = [[UIImage imageNamed:imageHArr[i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  460. tabBarItem.image = [[UIImage imageNamed:imageNArr[i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  461. UIViewController *curVC = viewControllers[i];
  462. curVC.tabBarItem = tabBarItem;
  463. }
  464. //tabBarController.tabBar.barTintColor = [UIColor hwColor:@"#F6F8FA"]; // 设置标签栏背景色
  465. tabBarController.tabBar.tintColor = [UIColor hwColor:@"#01B7EA"]; // 设置选中标签项的颜色
  466. tabBarController.tabBar.unselectedItemTintColor = [UIColor hwColor:@"#7C8196"]; // 设置未选中标签项的颜色
  467. tabBarController.tabBar.backgroundColor = [UIColor whiteColor];
  468. // [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor hwColor:@"#01B7EA"],NSForegroundColorAttributeName, [UIFont systemFontOfSize:12.0],NSFontAttributeName,nil] forState:UIControlStateSelected];
  469. // //[UIColor hwColor:@"#7C8196"]
  470. // [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor],NSForegroundColorAttributeName, [UIFont systemFontOfSize:12.0],NSFontAttributeName,nil] forState:UIControlStateNormal];
  471. BOOL haveOpenMask = [HWDataManager getBoolWithKey:Const_cloudPhone_Model_Open];
  472. if(haveOpenMask){
  473. //非隐私模式 直接进入推拉流页
  474. if(ksharedAppDelegate.DeviceThirdIdMod && !ksharedAppDelegate.DeviceThirdIdMod.data.isPrivacyMode){
  475. ksharedAppDelegate.isCloudPhoneModeNotPrivacyModeOpenType = YES;
  476. [cloudVC queryWebRtcMsgFun:YES];
  477. }
  478. else{
  479. ksharedAppDelegate.isCloudPhoneModeAndPrivacyModeOpenType = YES;
  480. }
  481. tabBarController.selectedIndex = 1;
  482. }
  483. ksharedAppDelegate.mainTabBar = tabBarController;
  484. self.window.rootViewController = tabBarController;
  485. [self.window makeKeyAndVisible];
  486. CGFloat second = 1.0;
  487. //BOOL haveOpenMask = [HWDataManager getBoolWithKey:Const_cloudPhone_Model_Open];
  488. if(haveOpenMask){
  489. second = 3;
  490. }
  491. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(second * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  492. [self beginShowAlertFun];
  493. });
  494. }
  495. #pragma mark 第一次连接成功
  496. - (void)firstDidLinkBoxFun
  497. {
  498. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  499. if (ksharedAppDelegate.mainTabBar) {
  500. NSArray *curArr = ksharedAppDelegate.mainTabBar.viewControllers;
  501. if (curArr.count >= 3) {
  502. BaseNavigationController *Nav = curArr[1];
  503. UIViewController *curVC = Nav.viewControllers.firstObject;
  504. if (![curVC isKindOfClass:[previewFileAndFolderViewController class]]) {
  505. return;
  506. }
  507. }
  508. }
  509. //[self initMainTabbarFun];
  510. [self enterMainVCFromScene];
  511. });
  512. }
  513. #pragma mark 处理进来是非隐私模式的情况
  514. - (void)HandleEnterNotPrivacyModeFun
  515. {
  516. #ifdef developJSQ
  517. NSInteger maskModel = 1;// [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  518. #else
  519. NSInteger maskModel = [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  520. #endif
  521. if (maskModel != 0){
  522. [HWDataManager setIntegerWithKey:Const_Mask_View_Model value:0];
  523. [iTools lc_setAlternateIconName:@"AppIcon1"];
  524. }
  525. }
  526. - (void)setPwdOk{
  527. [self enterMainVCFromScene];
  528. // NSArray *dataArray = [BaseModel bg_findAll:DB_BrowserWindows_TableName];
  529. //
  530. // if (dataArray.count == 0) { // 浏览器没有窗口
  531. // // 加载首页
  532. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  533. // vc.webUrl = Const_HomeUrl;
  534. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  535. // self.window.rootViewController = nvc;
  536. //
  537. // }else {
  538. // // 浏览器当前窗口索引ID
  539. // NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  540. // NSString *where = [NSString stringWithFormat:@"where %@=%ld",bg_sqlKey(@"ID"),(long)ID];
  541. // NSArray* finfAlls = [BaseModel bg_find:DB_BrowserWindows_TableName where:where];
  542. // BaseModel *model = finfAlls.firstObject;
  543. //
  544. // // 加载网页
  545. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  546. // vc.webUrl = model.webUrl;
  547. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  548. // self.window.rootViewController = nvc;
  549. // }
  550. }
  551. /** 登录界面 - 外部使用*/
  552. + (void)enterLoginVC {
  553. // SetPWDViewController *vc = [[SetPWDViewController alloc] init];
  554. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  555. // UIWindow *keyWindow = [iTools getKeyWindow];
  556. // keyWindow.rootViewController = nvc;
  557. }
  558. /** 主界面 - 外部使用 */
  559. + (void)enterMainVC {
  560. // AlbumHomeViewController *vc = [[AlbumHomeViewController alloc] init];
  561. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  562. // UIWindow *keyWindow = [iTools getKeyWindow];
  563. // keyWindow.rootViewController = nvc;
  564. }
  565. - (void)sceneDidDisconnect:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  566. HLog(@"sceneDidDisconnect");
  567. //[[connectDeviceManager shareInstance] disconnect];
  568. }
  569. - (void)sceneDidBecomeActive:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  570. HLog(@"sceneDidBecomeActive")
  571. }
  572. - (void)sceneWillResignActive:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  573. HLog(@"sceneWillResignActive")
  574. }
  575. - (void)sceneWillEnterForeground:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  576. HLog(@"sceneWillEnterForeground")
  577. [self beginShowAlertFun];
  578. }
  579. - (void)sceneDidEnterBackground:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  580. HLog(@"sceneDidEnterBackground")
  581. ksharedAppDelegate.didShowBoxHeartbeatAlertType = NO;
  582. BOOL isPrivacyMode = [HWDataManager getBoolWithKey:Const_Have_Add_Device_Privacy_Mode];
  583. if(ksharedAppDelegate.DeviceThirdIdMod){
  584. isPrivacyMode = ksharedAppDelegate.DeviceThirdIdMod.data.isPrivacyMode;
  585. }
  586. if(isPrivacyMode){//隐私模式 需要弹密码框 转竖屏
  587. BOOL isNeeddelayedType = NO;
  588. //这里强制竖屏 处理图片详情 和视频详情的横屏情况
  589. BaseNavigationController*mainNav = ksharedAppDelegate.mainTabBar.selectedViewController;
  590. if([mainNav isKindOfClass:[BaseNavigationController class]]){
  591. NSArray* vcArr = mainNav.viewControllers;
  592. if(vcArr.count >= 2){
  593. UIViewController *curVC = vcArr.lastObject;
  594. if([curVC isKindOfClass:[webRtcPlayerViewController class]]){
  595. webRtcPlayerViewController* vc = (webRtcPlayerViewController*)curVC;
  596. if(vc.isLan){
  597. ksharedAppDelegate.needToPushWebRtcVCType = YES;
  598. [vc exitCloudPhoneFun];
  599. }
  600. }
  601. else if([curVC isKindOfClass:[imageDetailsScrollViewController class]]
  602. ||[curVC isKindOfClass:[videoPlayByAVPlayerViewController class]]){
  603. //切换到竖屏
  604. ksharedAppDelegate.supportScreenRotateType = YES;
  605. [curVC hx_rotateToInterfaceOrientation:UIInterfaceOrientationPortrait];
  606. //ksharedAppDelegate.supportScreenRotateType = NO;
  607. isNeeddelayedType = YES;
  608. HLog(@"sceneDidEnterBackground 旋转屏幕为竖屏")
  609. }
  610. }
  611. }
  612. [self showCalculatorVC];
  613. }
  614. }
  615. - (void)scene:(UIScene *)scene continueUserActivity:(NSUserActivity *)userActivity {
  616. HLog(@"scene continueUserActivity")
  617. if([TencentOAuth CanHandleUniversalLink:userActivity.webpageURL]){
  618. [TencentOAuth HandleUniversalLink:userActivity.webpageURL];
  619. }
  620. else{
  621. [WXApi handleOpenUniversalLink:userActivity delegate:self];
  622. }
  623. }
  624. - (void)scene:(UIScene *)scene openURLContexts:(NSSet<UIOpenURLContext *> *)URLContexts {
  625. HLog(@"scene openURLContexts")
  626. NSEnumerator *enumerator = [URLContexts objectEnumerator];
  627. UIOpenURLContext *context;
  628. while (context = [enumerator nextObject]) {
  629. NSLog(@"context.URL =====%@",context.URL);
  630. //openprivacyxapp://page?param1=value1&param2=value2
  631. NSString *curStr = context.URL.absoluteString;
  632. if([curStr rangeOfString:@"openprivacyxapp://page"].location != NSNotFound){
  633. _getShareStr = curStr;
  634. [self delayedHandlShareAwakenAppBy:curStr];
  635. break;
  636. }
  637. else{
  638. [WXApi handleOpenURL:context.URL delegate:self];
  639. }
  640. //NSLog(@"context.options.sourceApplication ===== %@",context.options.sourceApplication);
  641. }
  642. _session = nil;
  643. _connectionOptions = nil;
  644. }
  645. - (void)delayedHandlShareAwakenAppBy:(NSString*)curStr{
  646. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  647. [self shareAwakenAppBy:curStr];
  648. });
  649. }
  650. #pragma mark 初始化数据库-DB_BrowserWindows_TableName
  651. - (void)initBrowserWindow {
  652. // 浏览器当前所有窗口
  653. NSArray *dataArray = [BaseModel bg_findAll:DB_BrowserWindows_TableName];
  654. // 浏览器当前窗口索引ID
  655. NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  656. NSString *IDValue = [NSString stringWithFormat:@"%ld", ID];
  657. NSString *where = [NSString stringWithFormat:@"where %@=%@",bg_sqlKey(@"ID"),bg_sqlValue(IDValue)];
  658. NSArray *modelArr = [BaseModel bg_find:DB_BrowserWindows_TableName where:where];
  659. if (dataArray.count == 0) { // 浏览器没有窗口
  660. BaseModel *model = [[BaseModel alloc] init];
  661. model.ID = 0;
  662. model.name = @"主页";
  663. // model.iconFile = imageUrl;
  664. model.webUrl = Const_HomeUrl;
  665. // 写入数据库
  666. model.bg_tableName = DB_BrowserWindows_TableName;
  667. [model bg_saveOrUpdateAsync:^(BOOL isSuccess) {
  668. HLog(@"BaseModel写入:%@", isSuccess ? @"成功":@"失败");
  669. }];
  670. // 浏览器当前窗口索引ID
  671. [HWDataManager setIntegerWithKey:BrowserWindowsCurrentID value:0];
  672. }else if (modelArr.count == 0) { // 新建窗口
  673. BaseModel *model = [[BaseModel alloc] init];
  674. model.ID = ID;
  675. model.name = @"主页";
  676. // model.iconFile = imageUrl;
  677. model.webUrl = Const_HomeUrl;
  678. // 写入数据库
  679. model.bg_tableName = DB_BrowserWindows_TableName;
  680. [model bg_saveOrUpdateAsync:^(BOOL isSuccess) {
  681. HLog(@"BaseModel写入:%@", isSuccess ? @"成功":@"失败");
  682. }];
  683. }else { // 更新窗口数据
  684. // 浏览器当前窗口索引ID
  685. // NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  686. //
  687. // BaseModel *model = [[BaseModel alloc] init];
  688. // model.ID = ID;
  689. // model.name = @"主页";
  690. //// model.iconFile = imageUrl;
  691. // model.webUrl = Const_HomeUrl;
  692. //
  693. // // 更新数据库
  694. // model.bg_tableName = DB_BrowserWindows_TableName;
  695. // [model bg_saveOrUpdateAsync:^(BOOL isSuccess) {
  696. // HLog(@"BaseModel更新: %@", isSuccess ? @"成功":@"失败");
  697. // }];
  698. }
  699. }
  700. #pragma mark 获取当前屏幕的截图
  701. //- (UIImage *)getScreenShotImage {
  702. // CGSize size = [UIScreen mainScreen].bounds.size;
  703. // CGFloat scale = [UIScreen mainScreen].scale;
  704. // UIGraphicsBeginImageContextWithOptions(size, YES, scale);
  705. // [self.window.layer renderInContext:UIGraphicsGetCurrentContext()];
  706. // UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
  707. // UIGraphicsEndImageContext();
  708. // return image;
  709. //}
  710. #pragma mark 计算器伪装视图
  711. /*CalculatorViewController*/
  712. - (void)showCalculatorVC{
  713. HLog(@"showCalculatorVC 处理密码框弹出")
  714. // if(SCREEN_W > SCREEN_H){
  715. // HLog(@"showCalculatorVC 屏幕还是横屏状态")
  716. // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  717. // [self showCalculatorVC];
  718. // });
  719. // return;
  720. // }
  721. ksharedAppDelegate.supportScreenRotateType = NO;
  722. if(ksharedAppDelegate.getSystemPermissType){
  723. HLog(@"检测到获取系统全进入后台");
  724. return;
  725. }
  726. BOOL haveGuide = [HWDataManager getBoolWithKey:Const_Have_Show_Guide];
  727. if (haveGuide) {
  728. ;
  729. }else {
  730. return;
  731. }
  732. BOOL isPrivacyMode = [HWDataManager getBoolWithKey:Const_Have_Add_Device_Privacy_Mode];
  733. if(ksharedAppDelegate.DeviceThirdIdMod){
  734. isPrivacyMode = ksharedAppDelegate.DeviceThirdIdMod.data.isPrivacyMode;
  735. }
  736. if(!isPrivacyMode){
  737. return;
  738. }
  739. //修复扫描已经有密码的合作 点击跳过因为网络弹框再次覆盖一次密码(需要输入两次密码)
  740. BaseNavigationController*curTopNav = (BaseNavigationController*)[iTools appRootViewController];
  741. if([curTopNav isKindOfClass:[BaseNavigationController class]]){
  742. NSArray *vcArr = [curTopNav viewControllers];
  743. if(vcArr && vcArr.count >0){
  744. UIViewController *lastVC = vcArr.lastObject;
  745. if([lastVC isKindOfClass:[inputPWDViewController class]]){
  746. return;
  747. }
  748. }
  749. }
  750. /*无有效时长直接返回不加载任何加密界面*/
  751. NSString *PwdStr = nil;
  752. NSDictionary *deviceDict = [HWDataManager getObjectWithKey:Const_Have_Add_Device];
  753. //实时拿到的密码 (每次打开或者更换设备 通过SN重新拿)
  754. if(ksharedAppDelegate.DeviceThirdIdMod.data.password){
  755. NSString *curPwd = ksharedAppDelegate.DeviceThirdIdMod.data.password;
  756. NSString*desPwdStr = [RSATool AES128Decrypt:curPwd key:AESCODEKEEYY];
  757. if(desPwdStr){
  758. PwdStr = desPwdStr;
  759. }
  760. }
  761. else{
  762. //本地密码本地判断 密码改在服务器保持
  763. if ([[deviceDict allKeys] containsObject:Const_Have_Add_Device_PWD]){
  764. PwdStr = [deviceDict objectForKey:Const_Have_Add_Device_PWD];
  765. }
  766. }
  767. if (!PwdStr || [PwdStr isEqualToString:@""])
  768. {
  769. return;
  770. }
  771. // BOOL haveOpenMask = [HWDataManager getBoolWithKey:Const_Mask_View_Open];
  772. // if (!haveOpenMask){
  773. // //输入密码界面
  774. // [self closeCalculatorVC];
  775. // _inputVC = [[inputPWDViewController alloc] init];
  776. // [self.window addSubview:_inputVC.view];
  777. // return;
  778. // }
  779. BOOL haveVaildTime = [HWDataManager getBoolWithKey:Const_Have_No_VaildTime];
  780. if (haveVaildTime == YES){/*无有效时间*/
  781. return;
  782. }
  783. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus != AFNetworkReachabilityStatusNotReachable)
  784. {
  785. if(!ksharedAppDelegate.DeviceThirdIdMod){
  786. return;
  787. }
  788. BOOL isPrivacyMode = ksharedAppDelegate.DeviceThirdIdMod.data.isPrivacyMode;
  789. if(!isPrivacyMode)
  790. {
  791. ksharedAppDelegate.isFirstInputPwdDone = YES;
  792. [[NSNotificationCenter defaultCenter] postNotificationName:didInputPWDNotification object:nil];
  793. return;
  794. }
  795. }
  796. #ifdef developJSQ
  797. NSInteger maskModel = 1;// [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  798. #else
  799. NSInteger maskModel = [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  800. #endif
  801. if (maskModel == 0){
  802. //输入密码界面
  803. [self closeCalculatorVC];
  804. _inputVC = [[inputPWDViewController alloc] init];
  805. [self.window addSubview:_inputVC.view];
  806. ksharedAppDelegate.isDidShowPwdType = YES;
  807. }
  808. else if (maskModel == 2){
  809. /*浏览器*/
  810. [self closeCalculatorVC];
  811. _webVC = [[HWWebViewController alloc] init];
  812. _webVC.pwd = PwdStr;
  813. _webVC.webUrl = @"https://baidu.com";
  814. [self.window addSubview:_webVC.view];
  815. ksharedAppDelegate.isDidShowPwdType = YES;
  816. }else{
  817. /*计算器*/
  818. [self closeCalculatorVC];
  819. _calculatorVC = [[CalculatorViewController alloc] init];
  820. _calculatorVC.pwd = PwdStr;
  821. [self.window addSubview:_calculatorVC.view];
  822. ksharedAppDelegate.isDidShowPwdType = YES;
  823. }
  824. [[NSNotificationCenter defaultCenter] postNotificationName:ShowPwdVCNotification object:nil];
  825. }
  826. - (void)closeCalculatorVC{
  827. ksharedAppDelegate.getSystemPermissType = NO;
  828. if (_calculatorVC){
  829. [_calculatorVC.view removeFromSuperview];
  830. }
  831. /*浏览器*/
  832. if (_webVC){
  833. [_webVC.view removeFromSuperview];
  834. }
  835. if(_inputVC){
  836. [_inputVC.view removeFromSuperview];
  837. }
  838. ksharedAppDelegate.isDidShowPwdType = NO;
  839. if(self->_session && self->_connectionOptions){
  840. [self scene:self->_session openURLContexts:self->_connectionOptions.URLContexts];
  841. }
  842. }
  843. - (NSString *)documentPathForAccount:(NSString *)account fileFolder:(NSString *)fileFolder {
  844. NSString *path = DocumentPath;
  845. if (account.length != 0) {
  846. path = [NSString stringWithFormat:@"%@/%@/",DocumentPath,account];
  847. }
  848. if ([fileFolder containsString:@"/"]) {
  849. NSString *path1 = [path stringByAppendingPathComponent:fileFolder];
  850. path1 = [path1 stringByDeletingLastPathComponent];
  851. NSError *error;
  852. if (![[NSFileManager defaultManager] fileExistsAtPath:path1]) {
  853. [[NSFileManager defaultManager] createDirectoryAtPath:path1 withIntermediateDirectories:YES attributes:nil error:&error];
  854. }
  855. }else{
  856. NSError *error;
  857. if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
  858. [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error];
  859. }
  860. }
  861. return [path stringByAppendingPathComponent:fileFolder];
  862. }
  863. - (void)startUseBtnBePressed{
  864. [self enterMainVCFromScene];
  865. // NSString *launchAppPWDPath = [self documentPathForAccount:@"" fileFolder:@"LaunchPWD"];
  866. // NSString *str = [[NSString alloc] initWithContentsOfFile:launchAppPWDPath encoding:(NSUTF8StringEncoding) error:nil];
  867. // if (!str || [str isEqualToString:@"0"])
  868. // {
  869. // SetUsePWDViewController *loginVC = [[SetUsePWDViewController alloc] init];
  870. // loginVC.delegate = self;
  871. // self.window.rootViewController = loginVC;
  872. //
  873. // return;
  874. // }
  875. //
  876. // NSArray *dataArray = [BaseModel bg_findAll:DB_BrowserWindows_TableName];
  877. //
  878. // if (dataArray.count == 0) { // 浏览器没有窗口
  879. // // 加载首页
  880. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  881. // vc.webUrl = Const_HomeUrl;
  882. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  883. // self.window.rootViewController = nvc;
  884. //
  885. // }else {
  886. // // 浏览器当前窗口索引ID
  887. // NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  888. // NSString *where = [NSString stringWithFormat:@"where %@=%ld",bg_sqlKey(@"ID"),(long)ID];
  889. // NSArray* finfAlls = [BaseModel bg_find:DB_BrowserWindows_TableName where:where];
  890. // BaseModel *model = finfAlls.firstObject;
  891. //
  892. // // 加载网页
  893. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  894. // vc.webUrl = model.webUrl;
  895. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  896. // self.window.rootViewController = nvc;
  897. // }
  898. }
  899. - (void)loginOk{
  900. [self enterMainVCFromScene];
  901. }
  902. - (void)guideOk:(NSNotification*)not{
  903. NSString *object = not.object;
  904. if(object && [object isEqualToString:@"isLoginAgainType"]){
  905. self.isLoginAgainType = YES;
  906. }
  907. //clear下载和上传的已经获取的数据
  908. // [[uploadFileManager shareInstance] suspendUploadFileFun:YES withModel:nil];
  909. // [uploadFileManager shareInstance].databaseArr = [NSMutableArray new];
  910. // [uploadFileManager shareInstance].fileModelDataArr = [NSMutableArray new];
  911. // [uploadFileManager shareInstance].curUploadFileDataModel.curUploadStateType = uploadStateWait;
  912. [[nasUploadFileManager shareInstance] suspendUploadFileFun:YES withModel:nil];
  913. [nasUploadFileManager shareInstance].databaseArr = nil;
  914. // [[downloadManager shareInstance] suspendDownloadFileFun:YES withModel:nil];
  915. // [downloadManager shareInstance].databaseArr = [NSMutableArray new];
  916. // [downloadManager shareInstance].downLoadFileModelDataArr = [NSMutableArray new];
  917. [[nasDownloadFileManager shareInstance] suspendDownloadFileFun:YES withModel:nil];
  918. [nasDownloadFileManager shareInstance].databaseArr = nil;
  919. //[[backupsFileManager shareInstance] suspendBackupsFileFun];
  920. [[nasBackupsManager shareInstance] suspendBackupsFileFun];
  921. //frp的下载
  922. [[customDownloadManager shareManager] suspendAllDownloadTask];
  923. NSString *uid =ksharedAppDelegate.DeviceThirdIdMod.data.sn;
  924. if(uid){
  925. }
  926. else{
  927. uid = @"";
  928. }
  929. [customDownloadManager shareManager].uid = uid;
  930. //盒子1音频在播放音乐,切换盒子2成功,仍在播放中
  931. [[DFPlayer sharedPlayer] df_deallocPlayer];
  932. [lastFileManager shareManager].uid = uid;
  933. [audioPlayListManager shareManager].uid = uid;
  934. [self enterMainVCFromScene];
  935. }
  936. #pragma mark 上报版本号信息
  937. -(void)reportVersionInfoFun
  938. {
  939. NSMutableDictionary *paraDict = [NSMutableDictionary new];
  940. NSString *vers = [iPhone appVersion];
  941. if(vers){
  942. [paraDict setValue:vers forKey:@"iosClientVersionNumber"];
  943. }
  944. NSDictionary *deviceDict = [HWDataManager getObjectWithKey:Const_Have_Add_Device];
  945. if (deviceDict && [[deviceDict allKeys] containsObject:Const_Have_Add_Device_SN]){
  946. NSString*snStr = deviceDict[Const_Have_Add_Device_SN];
  947. if(snStr){
  948. [paraDict setValue:snStr forKey:@"sn"];
  949. }
  950. else{
  951. return;
  952. }
  953. }
  954. else{
  955. return;;
  956. }
  957. // KWeakSelf
  958. [[netWorkManager shareInstance] CommonPostCallBackCode:reportVersionInfo Parameters:paraDict success:^(id _Nonnull responseObject) {
  959. } failure:^(NSError * _Nonnull error) {
  960. }];
  961. }
  962. #pragma mark 获取NAS相关信息
  963. -(void)getNASMsgFun
  964. {
  965. NSMutableDictionary *paraDict = [NSMutableDictionary new];
  966. NSString *SNStr = ksharedAppDelegate.DeviceThirdIdMod.data.changeSn;
  967. if(SNStr){
  968. [paraDict setValue:SNStr forKey:@"sn"];
  969. }
  970. else{
  971. return;;
  972. }
  973. KWeakSelf
  974. [[netWorkManager shareInstance] CommonGetWithCallBackCode:getIpFun Parameters:paraDict success:^(id _Nonnull responseObject){
  975. NASMsgModel *model = [[NASMsgModel alloc] initWithDictionary:responseObject error:nil];
  976. if(model){
  977. ksharedAppDelegate.NASMsgMod = model;
  978. }
  979. } failure:^(NSError * _Nonnull error) {
  980. }];
  981. }
  982. #pragma mark 主动上锁
  983. - (void)showLockViewFun:(NSNotification*)not
  984. {
  985. [self showCalculatorVC];
  986. }
  987. #pragma mark 进入设置密码
  988. //- (void)setPwdVCFun:(NSNotification*)not
  989. //{
  990. // _isNeedToShowSecretKey = YES;
  991. //}
  992. #pragma mark 忘记密码
  993. - (void)forgetPwdFun:(NSNotification*)not
  994. {
  995. /*忘记密码*/
  996. forgetPwdViewController *forgetPwdVC = [[forgetPwdViewController alloc] init];
  997. BaseNavigationController *forgetPwdVCNav = [[BaseNavigationController alloc] initWithRootViewController:forgetPwdVC];
  998. self.window.rootViewController = forgetPwdVCNav;
  999. }
  1000. #pragma mark 忘记密码返回
  1001. - (void)forgetPwdBackFun:(NSNotification*)not
  1002. {
  1003. // if(_preRootPlayerNav)
  1004. // {
  1005. // self.window.rootViewController = _preRootPlayerNav;
  1006. // }
  1007. // else{
  1008. [self enterMainVCFromScene];
  1009. //}
  1010. [self showCalculatorVC];
  1011. }
  1012. #pragma mark 忘记密码设置密码完成
  1013. - (void)forgetPwdDidSetPwdFun:(NSNotification*)not
  1014. {
  1015. // if(_preRootPlayerNav)
  1016. // {
  1017. // NSArray *vcArr = _preRootPlayerNav.viewControllers;
  1018. // if(vcArr.count > 2){
  1019. // [_preRootPlayerNav popToViewController:vcArr[1] animated:NO];
  1020. // }
  1021. // self.window.rootViewController = _preRootPlayerNav;
  1022. // }
  1023. // else{
  1024. [self enterMainVCFromScene];
  1025. //}
  1026. [self closeCalculatorVC];
  1027. ksharedAppDelegate.isFirstInputPwdDone = YES;
  1028. }
  1029. #pragma mark 扫码切换设备 scanChangeDeviceNotification
  1030. - (void)scanChangeDeviceFun:(NSNotification*)not
  1031. {
  1032. //TipsQRCodeForChangeDeviceViewController *nextVC = [[TipsQRCodeForChangeDeviceViewController alloc] init];
  1033. QRCodeScanForChangeDeviceViewController *nextVC = [[QRCodeScanForChangeDeviceViewController alloc] init];
  1034. nextVC.isRootVCType = YES;
  1035. BaseNavigationController *nextNav = [[BaseNavigationController alloc] initWithRootViewController:nextVC];
  1036. self.window.rootViewController = nextNav;
  1037. }
  1038. #pragma mark 扫码切换设备点击返回
  1039. - (void)scanChangeDeviceBackFun:(NSNotification*)not
  1040. {
  1041. // if(_preRootPlayerNav)
  1042. // {
  1043. // self.window.rootViewController = _preRootPlayerNav;
  1044. // }
  1045. // else{
  1046. [self enterMainVCFromScene];
  1047. //}
  1048. [self showCalculatorVC];
  1049. }
  1050. #pragma mark 网络异常弹框
  1051. -(void)showNetErrorAlertFun
  1052. {
  1053. NSInteger maskModel = [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  1054. if(maskModel !=0 && ksharedAppDelegate.isDidShowPwdType){
  1055. return;
  1056. }
  1057. NSString *linkErrTip = NSLocalizedString(@"player_link_fail_tip_type9",nil);
  1058. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable){
  1059. //linkErrTip = NSLocalizedString(@"player_link_fail_phone_Tips",nil);
  1060. _isNeedToStopWork = YES;
  1061. [self showNetErrorAlertType2Fun];
  1062. return;
  1063. }
  1064. linkErrTip = [[NSString alloc] initWithFormat:@"[9]%@",linkErrTip];
  1065. ComontAlretViewController *linkFailAlretVC= [[ComontAlretViewController alloc] initWithTiTle:nil
  1066. msg:linkErrTip
  1067. imageStr:nil
  1068. cancelTitle:NSLocalizedString(@"single_sign_on_exit",nil)
  1069. okTitle:NSLocalizedString(@"player_link_fail_tryAgain",nil) isOkBtnHighlight:YES
  1070. didClickOk:^{
  1071. //[self enterMainVCFromScene];
  1072. } didClickCancel:^{
  1073. exit(0);
  1074. }];
  1075. linkFailAlretVC.modalPresentationStyle = UIModalPresentationCustom;
  1076. [self.window.rootViewController presentViewController:linkFailAlretVC animated:YES completion:^{
  1077. linkFailAlretVC.view.superview.backgroundColor = [UIColor clearColor];
  1078. }];
  1079. }
  1080. #pragma mark 网络异常弹框
  1081. -(void)showNetErrorAlertType2Fun
  1082. {
  1083. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable){
  1084. NSString * linkErrTip = NSLocalizedString(@"netWork_error_tip_content",nil);
  1085. ComontAlretViewController *linkFailAlretVC= [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"netWork_error_tip_title",nil)
  1086. msg:linkErrTip
  1087. imageStr:nil
  1088. cancelTitle:NSLocalizedString(@"single_sign_on_exit",nil)
  1089. okTitle:nil isOkBtnHighlight:NO
  1090. didClickOk:^{
  1091. //[self enterMainVCFromScene];
  1092. } didClickCancel:^{
  1093. exit(0);
  1094. }];
  1095. linkFailAlretVC.modalPresentationStyle = UIModalPresentationCustom;
  1096. self.window.rootViewController = [UIViewController new];
  1097. [self.window.rootViewController presentViewController:linkFailAlretVC animated:YES completion:^{
  1098. linkFailAlretVC.view.superview.backgroundColor = [UIColor clearColor];
  1099. }];
  1100. }
  1101. }
  1102. - (void)gotoScanAginByThridMsgErrorFun:(NSInteger)errorCode
  1103. {
  1104. /*扫码界面*/
  1105. TipsQRCodeViewController *qrCodeVC = [[TipsQRCodeViewController alloc] init];
  1106. qrCodeVC.isNeedToShowAleatType = YES;
  1107. qrCodeVC.getSNMsgcode = errorCode;
  1108. BaseNavigationController *qrCodeVCNav = [[BaseNavigationController alloc] initWithRootViewController:qrCodeVC];
  1109. self.window.rootViewController = qrCodeVCNav;
  1110. }
  1111. #pragma mark 分享页面唤醒APP
  1112. - (void)shareAwakenAppBy:(NSString*)shareStr
  1113. {
  1114. //[[iToast makeText:shareStr] show];
  1115. NSArray * paraArr = [shareStr componentsSeparatedByString:@"&"];
  1116. if(!paraArr || paraArr.count==0){
  1117. return;
  1118. }
  1119. //type=save和download
  1120. NSString *type = nil;
  1121. NSString *fileIds = nil;
  1122. NSString *extractionCode = nil;
  1123. NSString *token = nil;
  1124. for (NSString*objectStr in paraArr) {
  1125. if([objectStr rangeOfString:@"type"].location != NSNotFound){
  1126. NSArray * objectArr = [objectStr componentsSeparatedByString:@"="];
  1127. if(objectArr.count == 2){
  1128. type = objectArr.lastObject;
  1129. continue;
  1130. }
  1131. }
  1132. else if([objectStr rangeOfString:@"fileIds"].location != NSNotFound){
  1133. NSArray * objectArr = [objectStr componentsSeparatedByString:@"="];
  1134. if(objectArr.count == 2){
  1135. fileIds = objectArr.lastObject;
  1136. continue;
  1137. }
  1138. }
  1139. else if([objectStr rangeOfString:@"extractionCode"].location != NSNotFound){
  1140. NSArray * objectArr = [objectStr componentsSeparatedByString:@"="];
  1141. if(objectArr.count == 2){
  1142. extractionCode = objectArr.lastObject;
  1143. continue;
  1144. }
  1145. }
  1146. else if([objectStr rangeOfString:@"token"].location != NSNotFound){
  1147. NSArray * objectArr = [objectStr componentsSeparatedByString:@"="];
  1148. if(objectArr.count == 2){
  1149. token = objectArr.lastObject;
  1150. continue;
  1151. }
  1152. }
  1153. }
  1154. if(!type || type.length ==0){
  1155. HLog(@"分享 type 获取错误");
  1156. return;
  1157. }
  1158. if(!fileIds || fileIds.length ==0){
  1159. HLog(@"分享 fileIds 获取错误");
  1160. return;
  1161. }
  1162. if(!token || token.length ==0){
  1163. HLog(@"分享 token 获取错误");
  1164. return;
  1165. }
  1166. [self getShareOneFileListFunByToken:token withFileIds:fileIds withExtractionCode:extractionCode withType:type];
  1167. }
  1168. #pragma mark 分享信息重新获取
  1169. - (void)getShareOneFileListFunByToken:(NSString*)token withFileIds:(NSString*)fileIds withExtractionCode:(NSString*)extractionCode withType:(NSString*)type
  1170. {
  1171. NSMutableDictionary*paraDict = [NSMutableDictionary new];
  1172. fileIds = [fileIds stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  1173. NSData *jsonData = [fileIds dataUsingEncoding:NSUTF8StringEncoding];;
  1174. NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
  1175. HLog(@"jsonArray:%@",jsonArray)
  1176. if(!jsonArray){
  1177. return;
  1178. }
  1179. [paraDict setValue:token forKey:@"token"];
  1180. [paraDict setValue:jsonArray forKey:@"fileIdList"];
  1181. [paraDict setValue:extractionCode forKey:@"extractionCode"];
  1182. KWeakSelf
  1183. [[netWorkManager shareInstance] CommonPostCallBackCode:queryOneShareInfoFun Parameters:paraDict success:^(id _Nonnull responseObject) {
  1184. queryOneShareModel*model = [[queryOneShareModel alloc] initWithDictionary:responseObject error:nil];
  1185. if(model && model.status == 0){
  1186. weakSelf.getShareStr = nil;
  1187. [weakSelf gotoVCByModel:model withType:type];
  1188. }
  1189. else{
  1190. }
  1191. } failure:^(NSError * _Nonnull error) {
  1192. }];
  1193. }
  1194. #pragma mark 跳转
  1195. - (void)gotoVCByModel:(queryOneShareModel*)model withType:(NSString*)type
  1196. {
  1197. if([type isEqualToString:@"save"]){
  1198. [self saveFileToBoxFunBy:model];
  1199. //数据埋点
  1200. [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Share_save"];
  1201. }
  1202. else if([type isEqualToString:@"download"]){
  1203. [self downloadFileToAppFunBy:model];
  1204. //数据埋点
  1205. [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Share_download"];
  1206. }
  1207. }
  1208. #pragma mark 保存文件到盒子
  1209. - (void)saveFileToBoxFunBy:(queryOneShareModel*)sharemodel
  1210. {
  1211. NSMutableDictionary*paraDict = [NSMutableDictionary new];
  1212. NSMutableArray *pathArr = [NSMutableArray new];
  1213. for (ShareFileDataModel*dataModel in sharemodel.data.fileListVOS){
  1214. [pathArr addObject:dataModel.fileUrl];
  1215. }
  1216. if (pathArr) {
  1217. NSString *jsonStr = [iTools toJsonStrWithArray:pathArr];
  1218. if(jsonStr){
  1219. [paraDict setValue:jsonStr forKey:@"urls"];
  1220. }
  1221. }
  1222. NSString * boxSaveDefaultPath = [HWDataManager getStringWithKey:stringKeyAddSn(Const_box_save_default_path)];
  1223. if(!boxSaveDefaultPath || boxSaveDefaultPath.length == 0){
  1224. boxSaveDefaultPath = Const_default_save_path;
  1225. [HWDataManager setStringWithKey:stringKeyAddSn(Const_box_save_default_path) value:boxSaveDefaultPath];
  1226. }
  1227. [paraDict setValue:boxSaveDefaultPath forKey:@"savePath"];
  1228. KWeakSelf
  1229. [[netWorkManager shareInstance] cloudPhoneGETCallBackCode:@"downFiles" Parameters:paraDict success:^(id _Nonnull responseObject) {
  1230. SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
  1231. if(model && model.status == 0){
  1232. [weakSelf gotoUploadFileRecordVCFunByType:2 withModel:sharemodel];
  1233. }
  1234. } failure:^(NSError * _Nonnull error) {
  1235. }];
  1236. }
  1237. #pragma mark 下载文件到手机
  1238. - (void)downloadFileToAppFunBy:(queryOneShareModel*)sharemodel
  1239. {
  1240. [self gotoUploadFileRecordVCFunByType:1 withModel:sharemodel];
  1241. }
  1242. #pragma mark 跳转传输列表
  1243. - (void)gotoUploadFileRecordVCFunByType:(NSInteger)type withModel:(queryOneShareModel*)sharemodel
  1244. {
  1245. KWeakSelf
  1246. if(type == 2){
  1247. [[boxSaveFileManager shareInstance] addBoxSaveRecordFunBy:sharemodel.data.fileListVOS complete:^(BOOL isSuccess) {
  1248. if(isSuccess){
  1249. mainBlock(^{
  1250. [weakSelf gotoUploadFileRecordVCFunByType:type];
  1251. });
  1252. }
  1253. }];
  1254. }
  1255. else if (type == 1){
  1256. if(![iTools checkFreeDiskSpaceInBytesIsOK:500*1024*1024]){
  1257. mainBlock(^{
  1258. [[iToast makeText:NSLocalizedString(@"phone_space_Insufficient",nil)] show];
  1259. });
  1260. return;
  1261. }
  1262. [[boxDownloadFileManager shareInstance] addBoxDownloadRecordFunBy:sharemodel.data.fileListVOS complete:^(BOOL isSuccess) {
  1263. if(isSuccess){
  1264. mainBlock(^{
  1265. [weakSelf gotoUploadFileRecordVCFunByType:type];
  1266. });
  1267. }
  1268. }];
  1269. }
  1270. }
  1271. - (void)gotoUploadFileRecordVCFunByType:(NSInteger)type
  1272. {
  1273. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  1274. vc.isReceiveType = type;
  1275. BaseNavigationController*mainNav = ksharedAppDelegate.mainTabBar.selectedViewController;
  1276. if([mainNav isKindOfClass:[BaseNavigationController class]]){
  1277. [mainNav pushViewController:vc animated:YES];
  1278. [[UIApplication sharedApplication] setStatusBarHidden:NO];
  1279. }
  1280. }
  1281. #pragma mark UITabBarControllerDelegate
  1282. - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
  1283. {
  1284. NSInteger index = tabBarController.selectedIndex;
  1285. int eventType = 1;
  1286. NSString* eventValue = @"Nas";
  1287. if(index == 0){
  1288. eventValue = @"Nas";
  1289. }
  1290. else if(index == 1){
  1291. eventValue = @"Cloud";
  1292. }
  1293. else if(index == 2){
  1294. eventValue = @"Home";
  1295. }
  1296. //数据埋点
  1297. [[netWorkManager shareInstance] DataEmbeddingPointBy:eventType withEventValue:eventValue];
  1298. }
  1299. - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
  1300. {
  1301. if(ksharedAppDelegate.isCloudPhoneModeNotPrivacyModeOpenType
  1302. || ksharedAppDelegate.isCloudPhoneModeAndPrivacyModeOpenType
  1303. || ksharedAppDelegate.needToPushWebRtcVCType){
  1304. return NO;
  1305. }
  1306. return YES;
  1307. }
  1308. #pragma mark 弹框逻辑放到这里
  1309. //优先级:1.强制盒子更新弹窗
  1310. // 2.APP版本更新弹窗 > 新手引导弹窗 > 通知公告弹窗
  1311. - (void)beginShowAlertFun
  1312. {
  1313. //
  1314. if (!ksharedAppDelegate.mainTabBar) {
  1315. return;
  1316. }
  1317. //1.隐私模式密码界面 3秒检测一次是否输入完成密码了
  1318. if(!ksharedAppDelegate.isFirstInputPwdDone){
  1319. KWeakSelf
  1320. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1321. [weakSelf beginShowAlertFun];
  1322. });
  1323. return;
  1324. }
  1325. // 强制盒子更新弹窗
  1326. [self checkUpgradeInfoFun];
  1327. }
  1328. #pragma mark 弹框流程 1 检测盒子镜像更新弹窗->1.4.4改为从服务器请求
  1329. - (void)checkUpgradeInfoFun
  1330. {
  1331. NSMutableDictionary *paraDict = [NSMutableDictionary dictionary];
  1332. [paraDict setValue:@"ota" forKey:@"type"];
  1333. KWeakSelf
  1334. [[netWorkManager shareInstance] CommonPostCallBackCode:queryUpgradeInfo Parameters:paraDict success:^(id _Nonnull responseObject) {
  1335. UpgradeInfoModel *model = [[UpgradeInfoModel alloc] initWithDictionary:responseObject error:nil];
  1336. if (model && model.status == 0) {
  1337. weakSelf.otaUpgradeInfoModel = model;
  1338. [weakSelf handelUpgradeInfoFun];
  1339. }
  1340. else
  1341. {
  1342. //2. APP版本更新弹窗
  1343. [weakSelf checkVersionFun];
  1344. }
  1345. } failure:^(NSError * _Nonnull error) {
  1346. KWeakSelf
  1347. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1348. [weakSelf checkUpgradeInfoFun];
  1349. });
  1350. }];
  1351. }
  1352. #pragma mark 弹框流程 1 强制盒子更新弹窗
  1353. - (void)handelUpgradeInfoFun
  1354. {
  1355. //self.otaUpgradeInfoModel.data.status = 1;
  1356. if(self.otaUpgradeInfoModel.data.status < 1){ //-1=没有更新 0=下载中
  1357. //2. APP版本更新弹窗
  1358. [self checkVersionFun];
  1359. }
  1360. else{
  1361. KWeakSelf
  1362. if(self.otaUpgradeInfoModel.data.status < 6){
  1363. [self showImageViewRenewTipViewFun];
  1364. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1365. [weakSelf checkUpgradeInfoFun];
  1366. });
  1367. }
  1368. else if(self.otaUpgradeInfoModel.data.status == 6){//升级完成
  1369. if(RenewTipView){
  1370. [self showImageViewRenewTipViewFun];
  1371. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1372. [weakSelf OTAUpdateDoneFun];
  1373. });
  1374. }
  1375. else{
  1376. [self OTAUpdateDoneFun];
  1377. }
  1378. }
  1379. else if(self.otaUpgradeInfoModel.data.status == 201){//升级失败
  1380. //显示升级失败
  1381. [self OTAUpdateFailFun];
  1382. }
  1383. else{
  1384. //2. APP版本更新弹窗
  1385. [self checkVersionFun];
  1386. }
  1387. }
  1388. }
  1389. #pragma mark 弹框流程 1 强制盒子更新弹窗
  1390. - (void)showImageViewRenewTipViewFun
  1391. {
  1392. //密码框界面 拦着 不给弹出
  1393. if(ksharedAppDelegate.isDidShowPwdType){
  1394. //didGetSysInfoType = NO;
  1395. KWeakSelf
  1396. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1397. [weakSelf showImageViewRenewTipViewFun];
  1398. });
  1399. return;
  1400. }
  1401. if(RenewTipView){
  1402. RenewTipView.status = _otaUpgradeInfoModel.data.status;
  1403. return;
  1404. }
  1405. BOOL haveOpenMask = [HWDataManager getBoolWithKey:Const_cloudPhone_Model_Open];
  1406. CGFloat second = 0.1;
  1407. if(haveOpenMask){
  1408. second = 1.5;
  1409. [[NSNotificationCenter defaultCenter] postNotificationName:needToPoPCloudPhoneVCNotification object:nil];
  1410. }
  1411. KWeakSelf
  1412. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(second * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1413. self->RenewTipView = [[imageVersionRenewTipView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H)];
  1414. [ksharedAppDelegate.window addSubview:self->RenewTipView];
  1415. self->RenewTipView.status = self->_otaUpgradeInfoModel.data.status;
  1416. //[self.view bringSubviewToFront:RenewTipView];
  1417. self->RenewTipView.didClickUpdateNowFun = ^{
  1418. [weakSelf otaUpdateNowFun];
  1419. };
  1420. self->RenewTipView.didClickCloseFun = ^{
  1421. [weakSelf didClickRenewTipViewCloseFun];
  1422. };
  1423. });
  1424. }
  1425. - (void)didClickRenewTipViewCloseFun{
  1426. RenewTipView = nil;
  1427. }
  1428. #pragma mark 弹框流程 1 盒子更新弹窗 点击立即更新
  1429. - (void)otaUpdateNowFun
  1430. {
  1431. NSMutableDictionary *paraDict = [NSMutableDictionary dictionary];
  1432. [paraDict setValue:@"ota" forKey:@"type"];
  1433. [paraDict setValue:@2 forKey:@"status"];
  1434. KWeakSelf
  1435. [[netWorkManager shareInstance] CommonPostCallBackCode:upgradeDetailAdd Parameters:paraDict success:^(id _Nonnull responseObject) {
  1436. SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
  1437. if (model && model.status == 0) {
  1438. [weakSelf checkUpgradeInfoFun];
  1439. }
  1440. else
  1441. {
  1442. [weakSelf checkVersionFun];
  1443. }
  1444. } failure:^(NSError * _Nonnull error) {
  1445. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1446. [weakSelf otaUpdateNowFun];
  1447. });
  1448. }];
  1449. //1.点击更新 标志 30分别 不谈 心跳弹框
  1450. long seconds = [iTools getNowTimeStamp];
  1451. NSNumber *secondsNum = [NSNumber numberWithLong:seconds];
  1452. if(secondsNum){
  1453. [HWDataManager setNumberWithKey:stringKeyAddSn(@"disenable_type1_BoxHeartbeat") value:secondsNum];
  1454. }
  1455. }
  1456. #pragma mark 弹框流程 1 OTA升级完成
  1457. - (void)OTAUpdateDoneFun
  1458. {
  1459. //密码框界面 拦着 不给弹出
  1460. if(ksharedAppDelegate.isDidShowPwdType){
  1461. KWeakSelf
  1462. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1463. [weakSelf OTAUpdateDoneFun];
  1464. });
  1465. return;
  1466. }
  1467. if(RenewTipView){
  1468. [RenewTipView removeFromSuperview];
  1469. RenewTipView = nil;
  1470. }
  1471. if (imageVersionUpdateDoneV) {
  1472. [imageVersionUpdateDoneV removeFromSuperview];
  1473. imageVersionUpdateDoneV = nil;
  1474. }
  1475. //显示OTA完成页面
  1476. imageVersionUpdateDoneV = [[imageVersionUpdateDoneView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H)];
  1477. [ksharedAppDelegate.window addSubview:imageVersionUpdateDoneV];
  1478. //[self.view bringSubviewToFront:curView];
  1479. KWeakSelf
  1480. imageVersionUpdateDoneV.didClickUpdateDoneFun = ^{
  1481. [weakSelf closeOTAUpdateDoneFun];
  1482. };
  1483. }
  1484. #pragma mark 弹框流程 1 OTA升级失败
  1485. - (void)OTAUpdateFailFun
  1486. {
  1487. //密码框界面 拦着 不给弹出
  1488. if(ksharedAppDelegate.isDidShowPwdType){
  1489. KWeakSelf
  1490. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1491. [weakSelf OTAUpdateFailFun];
  1492. });
  1493. return;
  1494. }
  1495. if(RenewTipView){
  1496. [RenewTipView removeFromSuperview];
  1497. RenewTipView = nil;
  1498. }
  1499. if (imageVersionUpdateFailV) {
  1500. [imageVersionUpdateFailV removeFromSuperview];
  1501. imageVersionUpdateFailV = nil;
  1502. }
  1503. //显示OTA完成页面
  1504. imageVersionUpdateFailV = [[imageVersionUpdateFailView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H)];
  1505. [ksharedAppDelegate.window addSubview:imageVersionUpdateFailV];
  1506. //[self.view bringSubviewToFront:curView];
  1507. KWeakSelf
  1508. imageVersionUpdateFailV.didClickUpdateDoneFun = ^{
  1509. [weakSelf closeOTAUpdateDoneFun];
  1510. };
  1511. }
  1512. #pragma mark 弹框流程 1 盒子更新弹窗 关闭弹窗
  1513. - (void)closeOTAUpdateDoneFun
  1514. {
  1515. NSMutableDictionary *paraDict = [NSMutableDictionary dictionary];
  1516. [paraDict setValue:@"ota" forKey:@"type"];
  1517. [paraDict setValue:@1 forKey:@"popButton"];
  1518. KWeakSelf
  1519. [[netWorkManager shareInstance] CommonPostCallBackCode:updateOTAPopButton Parameters:paraDict success:^(id _Nonnull responseObject) {
  1520. SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
  1521. if (model && model.status == 0) {
  1522. }
  1523. else
  1524. {
  1525. }
  1526. [weakSelf checkVersionFun];
  1527. } failure:^(NSError * _Nonnull error) {
  1528. [weakSelf checkVersionFun];
  1529. }];
  1530. }
  1531. #pragma mark 弹框流程 2 APP版本更新弹窗
  1532. - (void)checkVersionFun
  1533. {
  1534. //[self getVersion];
  1535. [self getLastNoticeFun];
  1536. }
  1537. #pragma mark 弹框流程 4 通知公告弹窗
  1538. - (void)getLastNoticeFun
  1539. {
  1540. NSMutableDictionary *paraDict = [NSMutableDictionary dictionary];
  1541. [paraDict setValue:@"Private-X" forKey:@"productType"];
  1542. [paraDict setValue:@"ios" forKey:@"type"];
  1543. [[netWorkManager shareInstance] CommonPostCallBackCode:queryOneNotice Parameters:paraDict success:^(id _Nonnull responseObject) {
  1544. noticeModel *model = [[noticeModel alloc] initWithDictionary:responseObject error:nil];
  1545. //test code
  1546. // model.status = 0;
  1547. // model.data = [noticeDataModel new];
  1548. // model.data.curNoticeId = @"1111";
  1549. // model.data.title = @"版本升级通知公告";
  1550. // model.data.content = @"1.偶现挤下线问题";
  1551. // model.data.content = @"1.偶现挤下线问题\n2.本地网络弹框\n3.访问相册权限之类的系统弹框会触发进入后台流程---显示输入密码框\n4.上传偶现UI刷新异常(数据库是正常的)\n5.偶现上传文件损坏\n6.链接不稳定问题(websock偶尔会不断重连\n7.进入设置页面读取数据偶现闪退!!!!\n8.本地网络弹框\n9.访问相册权限之类的系统弹框会触发进入后台流程---显示输入密码框\n10.上传偶现UI刷新异常(数据库是正常的)\n11.偶现上传文件损坏\n12.链接不稳定问题(websock偶尔会不断重连)\n13.进入设置页面读取数据偶现闪退!!!!\n14.本地网络弹框\n15.访问相册权限之类的系统弹框会触发进入后台流程\n16.上传偶现UI刷新异常(数据库是正常的)";//\n17.偶现上传文件损坏\n18.链接不稳定问题(websock偶尔会不断重连\n19.进入设置页面读取数据偶现闪退!!!!\n20.本地网络弹框\n21.访问相册权限之类的系统弹框会触发进入后台流程\n22.上传偶现UI刷新异常(数据库是正常的)\n23.偶现上传文件损坏\n24.链接不稳定问题(websock偶尔会不断重连)\n25.进入设置页面读取数据偶现闪退!!!!\n26.本地网络弹框\n27.访问相册权限之类的系统弹框会触发进入后台流程\n28.上传偶现UI刷新异常(数据库是正常的)\n29.偶现上传文件损坏\n30.链接不稳定问题(websock偶尔会不断重连)\n31.进入设置页面读取数据偶现闪退!!!!";
  1552. if (model && model.data && model.status == 0) {
  1553. [self showHaveNoticeViewBy:model];
  1554. }
  1555. else
  1556. {
  1557. }
  1558. } failure:^(NSError * _Nonnull error) {
  1559. HLog(@"%@", error);
  1560. }];
  1561. }
  1562. - (void)showHaveNoticeViewBy:(noticeModel*)model
  1563. {
  1564. //密码框界面 拦着 不给弹出
  1565. if(ksharedAppDelegate.isDidShowPwdType){
  1566. KWeakSelf
  1567. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1568. [weakSelf showHaveNoticeViewBy:model];
  1569. });
  1570. return;
  1571. }
  1572. HaveNoticeView * noticeView = [HaveNoticeView shardInstance];
  1573. NSString * preShowID = [HWDataManager getStringWithKey:Const_did_show_Notice_ID];
  1574. if(noticeView.isShow
  1575. || !model
  1576. || [preShowID isEqualToString:model.data.curNoticeId]){
  1577. return;
  1578. }
  1579. noticeView.curNoticeModel = model;
  1580. //异常处理
  1581. if(![iTools getKeyWindow]){
  1582. return;
  1583. }
  1584. [[iTools getKeyWindow] addSubview:noticeView];
  1585. [noticeView mas_makeConstraints:^(MASConstraintMaker *make) {
  1586. make.top.mas_equalTo(0);
  1587. make.left.mas_equalTo(0);
  1588. make.right.mas_equalTo(0);
  1589. make.bottom.mas_equalTo(0);
  1590. }];
  1591. noticeView.alpha = 0.0;
  1592. [UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^ {
  1593. noticeView.alpha = 1.0;
  1594. } completion:^(BOOL finished) {
  1595. }];
  1596. }
  1597. @end