SceneDelegate.m 70 KB

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