SceneDelegate.m 75 KB

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