SceneDelegate.m 74 KB

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