SceneDelegate.m 75 KB

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