SceneDelegate.m 75 KB

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