SceneDelegate.m 76 KB

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