SceneDelegate.m 70 KB

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