SceneDelegate.m 75 KB

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