SceneDelegate.m 76 KB

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