SceneDelegate.m 74 KB

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