SceneDelegate.m 74 KB

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