SceneDelegate.m 74 KB

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