SceneDelegate.m 76 KB

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