SceneDelegate.m 76 KB

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