SceneDelegate.m 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493
  1. //
  2. // SceneDelegate.m
  3. //
  4. //
  5. // Created by yhw 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 "SafeForKey.h"
  14. #import "TipsQRCodeViewController.h"
  15. #import "SetPWDFirstViewController.h"
  16. #import "inputPWDViewController.h"
  17. #import "customLaunchView.h"
  18. #import "RSATool.h"
  19. #import "forgetPwdViewController.h"
  20. #import "TipsQRCodeForChangeDeviceViewController.h"
  21. #import "AFNetworkReachabilityManager.h"
  22. #import "ComontAlretViewController.h"
  23. #import "uploadFileManager.h"
  24. //#import "downloadManager.h"
  25. #import "nasDownloadFileManager.h"
  26. //#import "backupsFileManager.h"
  27. #import "nasBackupsManager.h"
  28. #import "iPhone.h"
  29. #import <WXApi.h>
  30. #import <TencentOpenAPI/QQApiInterface.h>
  31. #import <TencentOpenAPI/TencentOAuth.h>
  32. #import "NASMsgModel.h"
  33. #import "queryOneShareModel.h"
  34. #import "boxSaveFileManager.h"
  35. #import "boxDownloadFileManager.h"
  36. #import "NASViewController.h"
  37. #import "cloudPhoneViewController.h"
  38. #import "mineViewController.h"
  39. #import "lastFileManager.h"
  40. #import "customDownloadManager.h"
  41. #import "audioPlayListManager.h"
  42. #import "QRCodeScanForChangeDeviceViewController.h"
  43. #import "customToastVew.h"
  44. #import "DFPlayer.h"
  45. #import "UIInterface+HXRotation.h"
  46. #import "imageDetailsScrollViewController.h"
  47. #import "videoPlayByAVPlayerViewController.h"
  48. #import "pingManager.h"
  49. #import "webRtcPlayerViewController.h"
  50. @interface SceneDelegate ()<SetUsePWDViewControllerDelegate,GuideViewControllerDelegate,UITabBarControllerDelegate>
  51. @property(nonatomic, strong) CalculatorViewController *calculatorVC;
  52. @property(nonatomic, strong) HWWebViewController *webVC;
  53. @property(nonatomic, strong) inputPWDViewController *inputVC;
  54. @property(nonatomic, strong) customLaunchView *customLaunchV;//
  55. @property(nonatomic, strong) BaseNavigationController *preRootPlayerNav;
  56. @property(nonatomic, assign) bool isQRCodeType;//第一次 扫码进来的
  57. //@property(nonatomic, assign) bool isNeedToShowSecretKey;//扫码进来的SN 没有密码 则需要显示秘钥
  58. @property (nonatomic, assign) BOOL isLoginAgainType;// 单点登录 点重新登录进来的
  59. @property (nonatomic, assign) BOOL isNeedToStopWork;// 无网络报错
  60. @property(nonatomic, copy) NSString *getShareStr;//拿到分享的字符串
  61. @property (nonatomic, assign) BOOL isFirstOpenInLaunch;//启动页停两秒
  62. //冷启动分享跳入用
  63. @property(nonatomic, strong) UISceneSession *session;
  64. @property(nonatomic, strong) UISceneConnectionOptions *connectionOptions;
  65. @end
  66. @implementation SceneDelegate
  67. - (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions API_AVAILABLE(ios(13.0)){
  68. HLog(@"willConnectToSession")
  69. if (scene) {
  70. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(guideOk:) name:GuideOkNotification object:nil];
  71. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showLockViewFun:) name:lockBypwdNotification object:nil];
  72. //[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setPwdVCFun:) name:setPwdNotification object:nil];
  73. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(forgetPwdFun:) name:forgetPwdNotification object:nil];
  74. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(forgetPwdBackFun:) name:forgetPwdBackNotification object:nil];
  75. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(forgetPwdDidSetPwdFun:) name:forgetPwdDidSetNotification object:nil];
  76. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scanChangeDeviceFun:) name:scanChangeDeviceNotification object:nil];
  77. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scanChangeDeviceBackFun:) name:scanChangeDeviceBackNotification object:nil];
  78. UIWindowScene *windowScene = (UIWindowScene *)scene;
  79. self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
  80. self.window.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
  81. _isFirstOpenInLaunch = YES;
  82. // 初始化数据库
  83. [self initBrowserWindow];
  84. // 加载主页面
  85. [self enterMainVCFromScene];
  86. //
  87. [self reportVersionInfoFun];
  88. [self.window makeKeyAndVisible];
  89. ksharedAppDelegate.window = self.window;
  90. //冷启动
  91. if(connectionOptions.URLContexts != nil){
  92. _session = session;
  93. _connectionOptions = connectionOptions;
  94. // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  95. // mainBlock(^{
  96. // [self scene:scene openURLContexts:connectionOptions.URLContexts];
  97. // });
  98. // });
  99. }
  100. }
  101. }
  102. /** 主界面 - 内部使用 */
  103. - (void)enterMainVCFromScene {
  104. // ConnectTestViewController *qrCodeVCNav = [[ConnectTestViewController alloc] init];
  105. // self.window.rootViewController = qrCodeVCNav;
  106. // return;/*临时测试*/
  107. if(_isNeedToStopWork){
  108. return;
  109. }
  110. /*先判断本地有无设备 无设备时需要先扫码添加设备*/
  111. NSDictionary *deviceDict = [HWDataManager getObjectWithKey:Const_Have_Add_Device];
  112. if (!deviceDict || ![[deviceDict allKeys] containsObject:Const_Have_Add_Device_SN]){
  113. //默认显示最近文件
  114. [HWDataManager setBoolWithKey:Const_last_file_show value:YES];
  115. /*扫码界面*/
  116. TipsQRCodeViewController *qrCodeVC = [[TipsQRCodeViewController alloc] init];
  117. BaseNavigationController *qrCodeVCNav = [[BaseNavigationController alloc] initWithRootViewController:qrCodeVC];
  118. self.window.rootViewController = qrCodeVCNav;
  119. _isQRCodeType = YES;
  120. return;
  121. }
  122. NSString *SNStr = deviceDict[@"Const_Have_Add_Device_SN"];
  123. // GuideViewController
  124. BOOL haveGuide = [HWDataManager getBoolWithKey:Const_Have_Show_Guide];
  125. if (haveGuide) {
  126. ;
  127. }else {
  128. GuideViewController *guiDeVC = [[GuideViewController alloc] init];
  129. guiDeVC.delegate = self;
  130. guiDeVC.sn = SNStr;
  131. self.window.rootViewController = guiDeVC;
  132. return;
  133. }
  134. //BOOL haveOpenMask = [HWDataManager getBoolWithKey:Const_Mask_View_Open];
  135. #ifdef developJSQ
  136. NSInteger maskModel = 1;// [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  137. #else
  138. NSInteger maskModel = [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  139. #endif
  140. //添加默认启动图片
  141. if(!_customLaunchV && maskModel == 0){
  142. _customLaunchV = [[customLaunchView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H)];
  143. [self.window addSubview:_customLaunchV];
  144. }
  145. if(maskModel == 0 && _isFirstOpenInLaunch){
  146. //20240612 产品觉得 启动页太快了 要停两秒
  147. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  148. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable)
  149. {
  150. [[iToast makeText:NSLocalizedString(@"phone_network_fail_Tips",nil)] show];
  151. customToastVew *toastview = [customToastVew makeText:NSLocalizedString(@"phone_network_fail_Tips",nil)];
  152. [toastview show];
  153. [self->_customLaunchV addSubview:toastview];
  154. return;
  155. }
  156. [self getDeviceMsgInMainVCWith:deviceDict];
  157. });
  158. _isFirstOpenInLaunch = NO;
  159. }
  160. else{
  161. //延时等网络状态
  162. if(_isFirstOpenInLaunch){
  163. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  164. [self getDeviceMsgInMainVCWith:deviceDict];
  165. });
  166. _isFirstOpenInLaunch = NO;
  167. }
  168. else{
  169. [self getDeviceMsgInMainVCWith:deviceDict];
  170. }
  171. }
  172. //[self showNetErrorAlertType2Fun];
  173. }
  174. - (void)getDeviceMsgInMainVCWith:(NSDictionary*)deviceDict
  175. {
  176. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable)
  177. {
  178. BOOL isPrivacyMode = [HWDataManager getBoolWithKey:Const_Have_Add_Device_Privacy_Mode];
  179. NSInteger maskModel = [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  180. if(!isPrivacyMode && maskModel == 0){
  181. return;
  182. }
  183. [self initMainTabbarFun];
  184. [self showCalculatorVC];
  185. return;
  186. }
  187. KWeakSelf
  188. //有设备了先去做链接准备 // 80bec9c5
  189. NSString *SNStr = deviceDict[@"Const_Have_Add_Device_SN"];
  190. NSString *sdnId = ksharedAppDelegate.DeviceThirdIdMod.data.sdnId;
  191. if(SNStr && !sdnId){
  192. //webrtc方案
  193. NSMutableDictionary *paraDict = [NSMutableDictionary new];
  194. [paraDict setValue:SNStr forKey:@"sn"];
  195. KWeakSelf
  196. [[netWorkManager shareInstance] CommonGetWithCallBackCode:getThirdIdBySn Parameters:paraDict success:^(id _Nonnull responseObject) {
  197. DeviceThirdIdModel *model = [[DeviceThirdIdModel alloc] initWithDictionary:responseObject error:nil];
  198. if(model.status == 0
  199. && model.data)
  200. {//根据SN 获取到正确的信息
  201. ksharedAppDelegate.DeviceThirdIdMod = model;
  202. NSString*desPwdstr = [RSATool AES128Decrypt:model.data.password key:AESCODEKEEYY];
  203. /*密码保持在本地*/
  204. NSDictionary *deviceDict = [HWDataManager getObjectWithKey:Const_Have_Add_Device];
  205. NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithDictionary:deviceDict];
  206. [dict setObject:desPwdstr forKey:Const_Have_Add_Device_PWD];
  207. NSString *sdnid = model.data.sdnId;
  208. if(sdnid){
  209. [dict setObject:sdnid forKey:Const_Have_Add_Device_sdnid];
  210. }
  211. [HWDataManager setObjectWithKey:Const_Have_Add_Device_Privacy_Mode value:[NSNumber numberWithBool:model.data.isPrivacyMode]];
  212. [HWDataManager setObjectWithKey:Const_Have_Add_Device value:dict];
  213. [weakSelf enterMainVCFromSceneSecondStepFun];;
  214. //ping看上是否为内网情况
  215. [[pingManager shareManager] startPingDeviceIpFun];
  216. //获取webrtc相关信息
  217. [weakSelf queryWebRtcMsgFun];
  218. }
  219. else{
  220. //if(model.status == 201||model.status == 202 || model.status ==2){}
  221. [weakSelf gotoScanAginByThridMsgErrorFun:model.status];
  222. }
  223. } failure:^(NSError * _Nonnull error) {
  224. HLog("网络报错");
  225. mainBlock(^{
  226. [weakSelf showNetErrorAlertFun];
  227. [weakSelf enterMainVCFromSceneSecondStepFun];
  228. });
  229. }];
  230. }
  231. else{
  232. //ping看上是否为内网情况
  233. [[pingManager shareManager] startPingDeviceIpFun];
  234. if (!ksharedAppDelegate.DeviceWebRtcMsgMod) {
  235. //获取webrtc相关信息
  236. [weakSelf queryWebRtcMsgFun];
  237. }
  238. [self enterMainVCFromSceneSecondStepFun];
  239. }
  240. }
  241. #pragma mark 获取webrct 的链接信息
  242. -(void)queryWebRtcMsgFun
  243. {
  244. NSMutableDictionary *paraDict = [NSMutableDictionary new];
  245. KWeakSelf
  246. [[netWorkManager shareInstance] CommonPostCallBackCode:webrctQueryByClient Parameters:paraDict success:^(id _Nonnull responseObject){
  247. webRtcMsgModel *curModel = [[webRtcMsgModel alloc] initWithDictionary:responseObject error:nil];
  248. if(curModel && curModel.status == 0){
  249. ksharedAppDelegate.DeviceWebRtcMsgMod = curModel;
  250. [[webRtcManager shareManager] beginToLinkWebRtcFun];
  251. }
  252. else
  253. {
  254. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  255. [weakSelf queryWebRtcMsgFun];
  256. });
  257. }
  258. } failure:^(NSError * _Nonnull error) {
  259. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  260. [weakSelf queryWebRtcMsgFun];
  261. });
  262. }];
  263. }
  264. - (void)enterMainVCFromSceneSecondStepFun
  265. {
  266. //确保通过SN号拿到密码了
  267. //非扫码进入 进入到这里很可能还没联网拿到设备最新信息
  268. if(!ksharedAppDelegate.DeviceThirdIdMod
  269. &&!ksharedAppDelegate.DeviceWebRtcMsgMod){
  270. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  271. mainBlock(^{
  272. [self enterMainVCFromScene];
  273. });
  274. });
  275. return;
  276. }
  277. //是否已经有密码了 有就是输入密码 没有就是设置密码
  278. NSString *curPwd = ksharedAppDelegate.DeviceThirdIdMod.data.password;
  279. NSString * sdnId = ksharedAppDelegate.DeviceThirdIdMod.data.sdnId;
  280. if(!sdnId && !ksharedAppDelegate.DeviceWebRtcMsgMod){
  281. HLog(@"没有拿到 --sdnId:%@ --- DeviceWebRtcMsgMod:%@",sdnId,ksharedAppDelegate.DeviceWebRtcMsgMod);
  282. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  283. mainBlock(^{
  284. [self enterMainVCFromScene];
  285. });
  286. });
  287. return;
  288. }
  289. if(_customLaunchV){
  290. [_customLaunchV removeFromSuperview];
  291. _customLaunchV = nil;
  292. }
  293. if(curPwd && curPwd.length > 0){
  294. /*设置密码*/
  295. // inputPWDViewController *nextVC = [[inputPWDViewController alloc] init];
  296. // BaseNavigationController *nextVCNav = [[BaseNavigationController alloc] initWithRootViewController:nextVC];
  297. // self.window.rootViewController = nextVCNav;
  298. }
  299. else{
  300. /*没有设置密码*/
  301. SetPWDFirstViewController *qrCodeVC = [[SetPWDFirstViewController alloc] init];
  302. BaseNavigationController *qrCodeVCNav = [[BaseNavigationController alloc] initWithRootViewController:qrCodeVC];
  303. self.window.rootViewController = qrCodeVCNav;
  304. return;
  305. }
  306. //下载配置先处理
  307. [boxDownloadFileManager shareInstance];
  308. [lastFileManager shareManager].uid = ksharedAppDelegate.DeviceThirdIdMod.data.sn;
  309. [audioPlayListManager shareManager].uid = ksharedAppDelegate.DeviceThirdIdMod.data.sn;
  310. //获取NAS相关信息
  311. [self getNASMsgFun];
  312. [self initMainTabbarFun];
  313. self.isLoginAgainType = NO;
  314. __block BOOL isPrivacyMode = ksharedAppDelegate.DeviceThirdIdMod.data.isPrivacyMode;
  315. //KWeakSelf
  316. if(!_isQRCodeType){
  317. if(isPrivacyMode)
  318. {
  319. [self showCalculatorVC];
  320. }
  321. else{
  322. [self HandleEnterNotPrivacyModeFun];
  323. ksharedAppDelegate.isFirstInputPwdDone = YES;
  324. //playerRootVC.isPwdVCShow = NO;
  325. //[playerRootVC setShowImgAndVoiceTypeFun:YES];
  326. //[weakSelf shareAwakenAppBy:weakSelf.getShareStr];
  327. if(self->_session && self->_connectionOptions){
  328. [self scene:self->_session openURLContexts:self->_connectionOptions.URLContexts];
  329. }
  330. }
  331. //_isQRCodeType = NO;
  332. }
  333. else{
  334. if(isPrivacyMode)
  335. {
  336. [self showCalculatorVC];
  337. }
  338. else{
  339. [[webRtcManager shareManager] beginToLinkWebRtcFun];
  340. }
  341. }
  342. _isQRCodeType = NO;
  343. //数据埋点
  344. [[netWorkManager shareInstance] DataEmbeddingPointBy:1 withEventValue:@"Nas"];
  345. }
  346. #pragma mark 1.4.1 新增tabbar
  347. - (void)initMainTabbarFun
  348. {
  349. UITabBarController *tabBarController = [[UITabBarController alloc] init];
  350. tabBarController.delegate = self;
  351. NASViewController *NASVC = [[NASViewController alloc] init];
  352. BaseNavigationController *NasNav = [[BaseNavigationController alloc] initWithRootViewController:NASVC];
  353. cloudPhoneViewController *cloudVC = [[cloudPhoneViewController alloc] init];
  354. BaseNavigationController *cloudPhoneNav = [[BaseNavigationController alloc] initWithRootViewController:cloudVC];
  355. mineViewController *mineVC = [[mineViewController alloc] init];
  356. BaseNavigationController *mineNav = [[BaseNavigationController alloc] initWithRootViewController:mineVC];
  357. NSArray *viewControllers = @[NasNav, cloudPhoneNav,mineNav]; // 添加更多视图控制器
  358. tabBarController.viewControllers = viewControllers;
  359. NSString*phoneTitle = NSLocalizedString(@"tabbar_cloud_phone",nil);
  360. NSString*myTitle = NSLocalizedString(@"tabbar_my_title",nil);
  361. NSArray *titleArr = @[@"NAS",phoneTitle,myTitle];
  362. NSArray *imageNArr = @[@"tabbar_nas_N", @"tabbar_phone_N",@"tabbar_my_N"];
  363. NSArray *imageHArr = @[@"tabbar_nas_H", @"tabbar_phone_H",@"tabbar_my_H"];
  364. for (int i=0; i<viewControllers.count; i++) {
  365. UITabBarItem * tabBarItem = [UITabBarItem new];
  366. tabBarItem.title = titleArr[i];
  367. tabBarItem.selectedImage = [[UIImage imageNamed:imageHArr[i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  368. tabBarItem.image = [[UIImage imageNamed:imageNArr[i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  369. UIViewController *curVC = viewControllers[i];
  370. curVC.tabBarItem = tabBarItem;
  371. }
  372. //tabBarController.tabBar.barTintColor = [UIColor hwColor:@"#F6F8FA"]; // 设置标签栏背景色
  373. tabBarController.tabBar.tintColor = [UIColor hwColor:@"#FF9500"]; // 设置选中标签项的颜色
  374. tabBarController.tabBar.unselectedItemTintColor = [UIColor hwColor:@"#7C8196"]; // 设置未选中标签项的颜色
  375. tabBarController.tabBar.backgroundColor = [UIColor whiteColor];
  376. // [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor hwColor:@"#01B7EA"],NSForegroundColorAttributeName, [UIFont systemFontOfSize:12.0],NSFontAttributeName,nil] forState:UIControlStateSelected];
  377. // //[UIColor hwColor:@"#7C8196"]
  378. // [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor],NSForegroundColorAttributeName, [UIFont systemFontOfSize:12.0],NSFontAttributeName,nil] forState:UIControlStateNormal];
  379. BOOL haveOpenMask = [HWDataManager getBoolWithKey:Const_cloudPhone_Model_Open];
  380. if(haveOpenMask){
  381. //非隐私模式 直接进入推拉流页
  382. if(ksharedAppDelegate.DeviceThirdIdMod && !ksharedAppDelegate.DeviceThirdIdMod.data.isPrivacyMode){
  383. ksharedAppDelegate.isCloudPhoneModeNotPrivacyModeOpenType = YES;
  384. [cloudVC queryWebRtcMsgFun:YES];
  385. }
  386. else{
  387. ksharedAppDelegate.isCloudPhoneModeAndPrivacyModeOpenType = YES;
  388. }
  389. tabBarController.selectedIndex = 1;
  390. }
  391. ksharedAppDelegate.mainTabBar = tabBarController;
  392. self.window.rootViewController = tabBarController;
  393. [self.window makeKeyAndVisible];
  394. }
  395. #pragma mark 处理进来是非隐私模式的情况
  396. - (void)HandleEnterNotPrivacyModeFun
  397. {
  398. #ifdef developJSQ
  399. NSInteger maskModel = 1;// [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  400. #else
  401. NSInteger maskModel = [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  402. #endif
  403. if (maskModel != 0){
  404. [HWDataManager setIntegerWithKey:Const_Mask_View_Model value:0];
  405. [iTools lc_setAlternateIconName:@"AppIcon1"];
  406. }
  407. }
  408. - (void)setPwdOk{
  409. [self enterMainVCFromScene];
  410. // NSArray *dataArray = [BaseModel bg_findAll:DB_BrowserWindows_TableName];
  411. //
  412. // if (dataArray.count == 0) { // 浏览器没有窗口
  413. // // 加载首页
  414. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  415. // vc.webUrl = Const_HomeUrl;
  416. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  417. // self.window.rootViewController = nvc;
  418. //
  419. // }else {
  420. // // 浏览器当前窗口索引ID
  421. // NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  422. // NSString *where = [NSString stringWithFormat:@"where %@=%ld",bg_sqlKey(@"ID"),(long)ID];
  423. // NSArray* finfAlls = [BaseModel bg_find:DB_BrowserWindows_TableName where:where];
  424. // BaseModel *model = finfAlls.firstObject;
  425. //
  426. // // 加载网页
  427. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  428. // vc.webUrl = model.webUrl;
  429. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  430. // self.window.rootViewController = nvc;
  431. // }
  432. }
  433. /** 登录界面 - 外部使用*/
  434. + (void)enterLoginVC {
  435. // SetPWDViewController *vc = [[SetPWDViewController alloc] init];
  436. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  437. // UIWindow *keyWindow = [iTools getKeyWindow];
  438. // keyWindow.rootViewController = nvc;
  439. }
  440. /** 主界面 - 外部使用 */
  441. + (void)enterMainVC {
  442. // AlbumHomeViewController *vc = [[AlbumHomeViewController alloc] init];
  443. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  444. // UIWindow *keyWindow = [iTools getKeyWindow];
  445. // keyWindow.rootViewController = nvc;
  446. }
  447. - (void)sceneDidDisconnect:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  448. HLog(@"sceneDidDisconnect");
  449. }
  450. - (void)sceneDidBecomeActive:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  451. HLog(@"sceneDidBecomeActive")
  452. }
  453. - (void)sceneWillResignActive:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  454. HLog(@"sceneWillResignActive")
  455. }
  456. - (void)sceneWillEnterForeground:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  457. HLog(@"sceneWillEnterForeground")
  458. }
  459. - (void)sceneDidEnterBackground:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  460. HLog(@"sceneDidEnterBackground")
  461. BOOL isPrivacyMode = [HWDataManager getBoolWithKey:Const_Have_Add_Device_Privacy_Mode];
  462. if(ksharedAppDelegate.DeviceThirdIdMod){
  463. isPrivacyMode = ksharedAppDelegate.DeviceThirdIdMod.data.isPrivacyMode;
  464. }
  465. if(isPrivacyMode){//隐私模式 需要弹密码框 转竖屏
  466. BOOL isNeeddelayedType = NO;
  467. //这里强制竖屏 处理图片详情 和视频详情的横屏情况
  468. BaseNavigationController*mainNav = ksharedAppDelegate.mainTabBar.selectedViewController;
  469. if([mainNav isKindOfClass:[BaseNavigationController class]]){
  470. NSArray* vcArr = mainNav.viewControllers;
  471. if(vcArr.count >= 2){
  472. UIViewController *curVC = vcArr.lastObject;
  473. if([curVC isKindOfClass:[webRtcPlayerViewController class]]){
  474. webRtcPlayerViewController* vc = (webRtcPlayerViewController*)curVC;
  475. if(vc.isLan){
  476. ksharedAppDelegate.needToPushWebRtcVCType = YES;
  477. [vc exitCloudPhoneFun];
  478. }
  479. }
  480. else if([curVC isKindOfClass:[imageDetailsScrollViewController class]]
  481. ||[curVC isKindOfClass:[videoPlayByAVPlayerViewController class]]){
  482. //切换到竖屏
  483. ksharedAppDelegate.supportScreenRotateType = YES;
  484. [curVC hx_rotateToInterfaceOrientation:UIInterfaceOrientationPortrait];
  485. //ksharedAppDelegate.supportScreenRotateType = NO;
  486. isNeeddelayedType = YES;
  487. HLog(@"sceneDidEnterBackground 旋转屏幕为竖屏")
  488. }
  489. }
  490. }
  491. [self showCalculatorVC];
  492. }
  493. }
  494. - (void)scene:(UIScene *)scene continueUserActivity:(NSUserActivity *)userActivity {
  495. HLog(@"scene continueUserActivity")
  496. if([TencentOAuth CanHandleUniversalLink:userActivity.webpageURL]){
  497. [TencentOAuth HandleUniversalLink:userActivity.webpageURL];
  498. }
  499. else{
  500. [WXApi handleOpenUniversalLink:userActivity delegate:self];
  501. }
  502. }
  503. - (void)scene:(UIScene *)scene openURLContexts:(NSSet<UIOpenURLContext *> *)URLContexts {
  504. HLog(@"scene openURLContexts")
  505. NSEnumerator *enumerator = [URLContexts objectEnumerator];
  506. UIOpenURLContext *context;
  507. while (context = [enumerator nextObject]) {
  508. NSLog(@"context.URL =====%@",context.URL);
  509. //openprivacyxapp://page?param1=value1&param2=value2
  510. NSString *curStr = context.URL.absoluteString;
  511. if([curStr rangeOfString:@"openprivacyxapp://page"].location != NSNotFound){
  512. _getShareStr = curStr;
  513. [self delayedHandlShareAwakenAppBy:curStr];
  514. break;
  515. }
  516. else{
  517. [WXApi handleOpenURL:context.URL delegate:self];
  518. }
  519. //NSLog(@"context.options.sourceApplication ===== %@",context.options.sourceApplication);
  520. }
  521. _session = nil;
  522. _connectionOptions = nil;
  523. }
  524. - (void)delayedHandlShareAwakenAppBy:(NSString*)curStr{
  525. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  526. [self shareAwakenAppBy:curStr];
  527. });
  528. }
  529. #pragma mark 初始化数据库-DB_BrowserWindows_TableName
  530. - (void)initBrowserWindow {
  531. // 浏览器当前所有窗口
  532. NSArray *dataArray = [BaseModel bg_findAll:DB_BrowserWindows_TableName];
  533. // 浏览器当前窗口索引ID
  534. NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  535. NSString *IDValue = [NSString stringWithFormat:@"%ld", ID];
  536. NSString *where = [NSString stringWithFormat:@"where %@=%@",bg_sqlKey(@"ID"),bg_sqlValue(IDValue)];
  537. NSArray *modelArr = [BaseModel bg_find:DB_BrowserWindows_TableName where:where];
  538. if (dataArray.count == 0) { // 浏览器没有窗口
  539. BaseModel *model = [[BaseModel alloc] init];
  540. model.ID = 0;
  541. model.name = @"主页";
  542. // model.iconFile = imageUrl;
  543. model.webUrl = Const_HomeUrl;
  544. // 写入数据库
  545. model.bg_tableName = DB_BrowserWindows_TableName;
  546. [model bg_saveOrUpdateAsync:^(BOOL isSuccess) {
  547. HLog(@"BaseModel写入:%@", isSuccess ? @"成功":@"失败");
  548. }];
  549. // 浏览器当前窗口索引ID
  550. [HWDataManager setIntegerWithKey:BrowserWindowsCurrentID value:0];
  551. }else if (modelArr.count == 0) { // 新建窗口
  552. BaseModel *model = [[BaseModel alloc] init];
  553. model.ID = ID;
  554. model.name = @"主页";
  555. // model.iconFile = imageUrl;
  556. model.webUrl = Const_HomeUrl;
  557. // 写入数据库
  558. model.bg_tableName = DB_BrowserWindows_TableName;
  559. [model bg_saveOrUpdateAsync:^(BOOL isSuccess) {
  560. HLog(@"BaseModel写入:%@", isSuccess ? @"成功":@"失败");
  561. }];
  562. }else { // 更新窗口数据
  563. // 浏览器当前窗口索引ID
  564. // NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  565. //
  566. // BaseModel *model = [[BaseModel alloc] init];
  567. // model.ID = ID;
  568. // model.name = @"主页";
  569. //// model.iconFile = imageUrl;
  570. // model.webUrl = Const_HomeUrl;
  571. //
  572. // // 更新数据库
  573. // model.bg_tableName = DB_BrowserWindows_TableName;
  574. // [model bg_saveOrUpdateAsync:^(BOOL isSuccess) {
  575. // HLog(@"BaseModel更新: %@", isSuccess ? @"成功":@"失败");
  576. // }];
  577. }
  578. }
  579. #pragma mark 获取当前屏幕的截图
  580. //- (UIImage *)getScreenShotImage {
  581. // CGSize size = [UIScreen mainScreen].bounds.size;
  582. // CGFloat scale = [UIScreen mainScreen].scale;
  583. // UIGraphicsBeginImageContextWithOptions(size, YES, scale);
  584. // [self.window.layer renderInContext:UIGraphicsGetCurrentContext()];
  585. // UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
  586. // UIGraphicsEndImageContext();
  587. // return image;
  588. //}
  589. #pragma mark 计算器伪装视图
  590. /*CalculatorViewController*/
  591. - (void)showCalculatorVC{
  592. HLog(@"showCalculatorVC 处理密码框弹出")
  593. if(SCREEN_W > SCREEN_H){
  594. HLog(@"showCalculatorVC 屏幕还是横屏状态")
  595. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  596. [self showCalculatorVC];
  597. });
  598. return;
  599. }
  600. ksharedAppDelegate.supportScreenRotateType = NO;
  601. if(ksharedAppDelegate.getSystemPermissType){
  602. HLog(@"检测到获取系统全进入后台");
  603. return;
  604. }
  605. BOOL haveGuide = [HWDataManager getBoolWithKey:Const_Have_Show_Guide];
  606. if (haveGuide) {
  607. ;
  608. }else {
  609. return;
  610. }
  611. BOOL isPrivacyMode = [HWDataManager getBoolWithKey:Const_Have_Add_Device_Privacy_Mode];
  612. if(ksharedAppDelegate.DeviceThirdIdMod){
  613. isPrivacyMode = ksharedAppDelegate.DeviceThirdIdMod.data.isPrivacyMode;
  614. }
  615. if(!isPrivacyMode){
  616. return;
  617. }
  618. //修复扫描已经有密码的合作 点击跳过因为网络弹框再次覆盖一次密码(需要输入两次密码)
  619. BaseNavigationController*curTopNav = (BaseNavigationController*)[iTools appRootViewController];
  620. if([curTopNav isKindOfClass:[BaseNavigationController class]]){
  621. NSArray *vcArr = [curTopNav viewControllers];
  622. if(vcArr && vcArr.count >0){
  623. UIViewController *lastVC = vcArr.lastObject;
  624. if([lastVC isKindOfClass:[inputPWDViewController class]]){
  625. return;
  626. }
  627. }
  628. }
  629. /*无有效时长直接返回不加载任何加密界面*/
  630. NSString *PwdStr = nil;
  631. NSDictionary *deviceDict = [HWDataManager getObjectWithKey:Const_Have_Add_Device];
  632. //实时拿到的密码 (每次打开或者更换设备 通过SN重新拿)
  633. if(ksharedAppDelegate.DeviceThirdIdMod.data.password){
  634. NSString *curPwd = ksharedAppDelegate.DeviceThirdIdMod.data.password;
  635. NSString*desPwdStr = [RSATool AES128Decrypt:curPwd key:AESCODEKEEYY];
  636. if(desPwdStr){
  637. PwdStr = desPwdStr;
  638. }
  639. }
  640. else{
  641. //本地密码本地判断 密码改在服务器保持
  642. if ([[deviceDict allKeys] containsObject:Const_Have_Add_Device_PWD]){
  643. PwdStr = [deviceDict objectForKey:Const_Have_Add_Device_PWD];
  644. }
  645. }
  646. if (!PwdStr || [PwdStr isEqualToString:@""])
  647. {
  648. return;
  649. }
  650. // BOOL haveOpenMask = [HWDataManager getBoolWithKey:Const_Mask_View_Open];
  651. // if (!haveOpenMask){
  652. // //输入密码界面
  653. // [self closeCalculatorVC];
  654. // _inputVC = [[inputPWDViewController alloc] init];
  655. // [self.window addSubview:_inputVC.view];
  656. // return;
  657. // }
  658. BOOL haveVaildTime = [HWDataManager getBoolWithKey:Const_Have_No_VaildTime];
  659. if (haveVaildTime == YES){/*无有效时间*/
  660. return;
  661. }
  662. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus != AFNetworkReachabilityStatusNotReachable)
  663. {
  664. if(!ksharedAppDelegate.DeviceThirdIdMod){
  665. return;
  666. }
  667. BOOL isPrivacyMode = ksharedAppDelegate.DeviceThirdIdMod.data.isPrivacyMode;
  668. if(!isPrivacyMode)
  669. {
  670. ksharedAppDelegate.isFirstInputPwdDone = YES;
  671. [[NSNotificationCenter defaultCenter] postNotificationName:didInputPWDNotification object:nil];
  672. return;
  673. }
  674. }
  675. #ifdef developJSQ
  676. NSInteger maskModel = 1;// [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  677. #else
  678. NSInteger maskModel = [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  679. #endif
  680. if (maskModel == 0){
  681. //输入密码界面
  682. [self closeCalculatorVC];
  683. _inputVC = [[inputPWDViewController alloc] init];
  684. [self.window addSubview:_inputVC.view];
  685. ksharedAppDelegate.isDidShowPwdType = YES;
  686. }
  687. else if (maskModel == 2){
  688. /*浏览器*/
  689. [self closeCalculatorVC];
  690. _webVC = [[HWWebViewController alloc] init];
  691. _webVC.pwd = PwdStr;
  692. _webVC.webUrl = @"https://baidu.com";
  693. [self.window addSubview:_webVC.view];
  694. ksharedAppDelegate.isDidShowPwdType = YES;
  695. }else{
  696. /*计算器*/
  697. [self closeCalculatorVC];
  698. _calculatorVC = [[CalculatorViewController alloc] init];
  699. _calculatorVC.pwd = PwdStr;
  700. [self.window addSubview:_calculatorVC.view];
  701. ksharedAppDelegate.isDidShowPwdType = YES;
  702. }
  703. [[NSNotificationCenter defaultCenter] postNotificationName:ShowPwdVCNotification object:nil];
  704. }
  705. - (void)closeCalculatorVC{
  706. ksharedAppDelegate.getSystemPermissType = NO;
  707. if (_calculatorVC){
  708. [_calculatorVC.view removeFromSuperview];
  709. }
  710. /*浏览器*/
  711. if (_webVC){
  712. [_webVC.view removeFromSuperview];
  713. }
  714. if(_inputVC){
  715. [_inputVC.view removeFromSuperview];
  716. }
  717. ksharedAppDelegate.isDidShowPwdType = NO;
  718. if(self->_session && self->_connectionOptions){
  719. [self scene:self->_session openURLContexts:self->_connectionOptions.URLContexts];
  720. }
  721. }
  722. - (NSString *)documentPathForAccount:(NSString *)account fileFolder:(NSString *)fileFolder {
  723. NSString *path = DocumentPath;
  724. if (account.length != 0) {
  725. path = [NSString stringWithFormat:@"%@/%@/",DocumentPath,account];
  726. }
  727. if ([fileFolder containsString:@"/"]) {
  728. NSString *path1 = [path stringByAppendingPathComponent:fileFolder];
  729. path1 = [path1 stringByDeletingLastPathComponent];
  730. NSError *error;
  731. if (![[NSFileManager defaultManager] fileExistsAtPath:path1]) {
  732. [[NSFileManager defaultManager] createDirectoryAtPath:path1 withIntermediateDirectories:YES attributes:nil error:&error];
  733. }
  734. }else{
  735. NSError *error;
  736. if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
  737. [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error];
  738. }
  739. }
  740. return [path stringByAppendingPathComponent:fileFolder];
  741. }
  742. - (void)startUseBtnBePressed{
  743. [self enterMainVCFromScene];
  744. // NSString *launchAppPWDPath = [self documentPathForAccount:@"" fileFolder:@"LaunchPWD"];
  745. // NSString *str = [[NSString alloc] initWithContentsOfFile:launchAppPWDPath encoding:(NSUTF8StringEncoding) error:nil];
  746. // if (!str || [str isEqualToString:@"0"])
  747. // {
  748. // SetUsePWDViewController *loginVC = [[SetUsePWDViewController alloc] init];
  749. // loginVC.delegate = self;
  750. // self.window.rootViewController = loginVC;
  751. //
  752. // return;
  753. // }
  754. //
  755. // NSArray *dataArray = [BaseModel bg_findAll:DB_BrowserWindows_TableName];
  756. //
  757. // if (dataArray.count == 0) { // 浏览器没有窗口
  758. // // 加载首页
  759. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  760. // vc.webUrl = Const_HomeUrl;
  761. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  762. // self.window.rootViewController = nvc;
  763. //
  764. // }else {
  765. // // 浏览器当前窗口索引ID
  766. // NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  767. // NSString *where = [NSString stringWithFormat:@"where %@=%ld",bg_sqlKey(@"ID"),(long)ID];
  768. // NSArray* finfAlls = [BaseModel bg_find:DB_BrowserWindows_TableName where:where];
  769. // BaseModel *model = finfAlls.firstObject;
  770. //
  771. // // 加载网页
  772. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  773. // vc.webUrl = model.webUrl;
  774. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  775. // self.window.rootViewController = nvc;
  776. // }
  777. }
  778. - (void)loginOk{
  779. [self enterMainVCFromScene];
  780. }
  781. - (void)guideOk:(NSNotification*)not{
  782. NSString *object = not.object;
  783. if(object && [object isEqualToString:@"isLoginAgainType"]){
  784. self.isLoginAgainType = YES;
  785. }
  786. //clear下载和上传的已经获取的数据
  787. // [[uploadFileManager shareInstance] suspendUploadFileFun:YES withModel:nil];
  788. // [uploadFileManager shareInstance].databaseArr = [NSMutableArray new];
  789. // [uploadFileManager shareInstance].fileModelDataArr = [NSMutableArray new];
  790. // [uploadFileManager shareInstance].curUploadFileDataModel.curUploadStateType = uploadStateWait;
  791. [[nasUploadFileManager shareInstance] suspendUploadFileFun:YES withModel:nil];
  792. [nasUploadFileManager shareInstance].databaseArr = nil;
  793. // [[downloadManager shareInstance] suspendDownloadFileFun:YES withModel:nil];
  794. // [downloadManager shareInstance].databaseArr = [NSMutableArray new];
  795. // [downloadManager shareInstance].downLoadFileModelDataArr = [NSMutableArray new];
  796. [[nasDownloadFileManager shareInstance] suspendDownloadFileFun:YES withModel:nil];
  797. [nasDownloadFileManager shareInstance].databaseArr = nil;
  798. //[[backupsFileManager shareInstance] suspendBackupsFileFun];
  799. [[nasBackupsManager shareInstance] suspendBackupsFileFun];
  800. //frp的下载
  801. [[customDownloadManager shareManager] suspendAllDownloadTask];
  802. NSString *uid =ksharedAppDelegate.DeviceThirdIdMod.data.sn;
  803. if(uid){
  804. }
  805. else{
  806. uid = @"";
  807. }
  808. [customDownloadManager shareManager].uid = uid;
  809. //盒子1音频在播放音乐,切换盒子2成功,仍在播放中
  810. [[DFPlayer sharedPlayer] df_deallocPlayer];
  811. [lastFileManager shareManager].uid = uid;
  812. [audioPlayListManager shareManager].uid = uid;
  813. [self enterMainVCFromScene];
  814. }
  815. #pragma mark 上报版本号信息
  816. -(void)reportVersionInfoFun
  817. {
  818. NSMutableDictionary *paraDict = [NSMutableDictionary new];
  819. NSString *vers = [iPhone appVersion];
  820. if(vers){
  821. [paraDict setValue:vers forKey:@"iosClientVersionNumber"];
  822. }
  823. NSDictionary *deviceDict = [HWDataManager getObjectWithKey:Const_Have_Add_Device];
  824. if (deviceDict && [[deviceDict allKeys] containsObject:Const_Have_Add_Device_SN]){
  825. NSString*snStr = deviceDict[Const_Have_Add_Device_SN];
  826. if(snStr){
  827. [paraDict setValue:snStr forKey:@"sn"];
  828. }
  829. else{
  830. return;
  831. }
  832. }
  833. else{
  834. return;;
  835. }
  836. // KWeakSelf
  837. [[netWorkManager shareInstance] CommonPostCallBackCode:reportVersionInfo Parameters:paraDict success:^(id _Nonnull responseObject) {
  838. } failure:^(NSError * _Nonnull error) {
  839. }];
  840. }
  841. #pragma mark 获取NAS相关信息
  842. -(void)getNASMsgFun
  843. {
  844. NSMutableDictionary *paraDict = [NSMutableDictionary new];
  845. NSString *SNStr = ksharedAppDelegate.DeviceThirdIdMod.data.changeSn;
  846. if(SNStr){
  847. [paraDict setValue:SNStr forKey:@"sn"];
  848. }
  849. else{
  850. return;;
  851. }
  852. KWeakSelf
  853. [[netWorkManager shareInstance] CommonGetWithCallBackCode:getIpFun Parameters:paraDict success:^(id _Nonnull responseObject){
  854. NASMsgModel *model = [[NASMsgModel alloc] initWithDictionary:responseObject error:nil];
  855. if(model){
  856. ksharedAppDelegate.NASMsgMod = model;
  857. }
  858. } failure:^(NSError * _Nonnull error) {
  859. }];
  860. }
  861. #pragma mark 主动上锁
  862. - (void)showLockViewFun:(NSNotification*)not
  863. {
  864. [self showCalculatorVC];
  865. }
  866. #pragma mark 进入设置密码
  867. //- (void)setPwdVCFun:(NSNotification*)not
  868. //{
  869. // _isNeedToShowSecretKey = YES;
  870. //}
  871. #pragma mark 忘记密码
  872. - (void)forgetPwdFun:(NSNotification*)not
  873. {
  874. /*忘记密码*/
  875. forgetPwdViewController *forgetPwdVC = [[forgetPwdViewController alloc] init];
  876. BaseNavigationController *forgetPwdVCNav = [[BaseNavigationController alloc] initWithRootViewController:forgetPwdVC];
  877. self.window.rootViewController = forgetPwdVCNav;
  878. }
  879. #pragma mark 忘记密码返回
  880. - (void)forgetPwdBackFun:(NSNotification*)not
  881. {
  882. // if(_preRootPlayerNav)
  883. // {
  884. // self.window.rootViewController = _preRootPlayerNav;
  885. // }
  886. // else{
  887. [self enterMainVCFromScene];
  888. //}
  889. [self showCalculatorVC];
  890. }
  891. #pragma mark 忘记密码设置密码完成
  892. - (void)forgetPwdDidSetPwdFun:(NSNotification*)not
  893. {
  894. // if(_preRootPlayerNav)
  895. // {
  896. // NSArray *vcArr = _preRootPlayerNav.viewControllers;
  897. // if(vcArr.count > 2){
  898. // [_preRootPlayerNav popToViewController:vcArr[1] animated:NO];
  899. // }
  900. // self.window.rootViewController = _preRootPlayerNav;
  901. // }
  902. // else{
  903. [self enterMainVCFromScene];
  904. //}
  905. [self closeCalculatorVC];
  906. ksharedAppDelegate.isFirstInputPwdDone = YES;
  907. }
  908. #pragma mark 扫码切换设备 scanChangeDeviceNotification
  909. - (void)scanChangeDeviceFun:(NSNotification*)not
  910. {
  911. //TipsQRCodeForChangeDeviceViewController *nextVC = [[TipsQRCodeForChangeDeviceViewController alloc] init];
  912. QRCodeScanForChangeDeviceViewController *nextVC = [[QRCodeScanForChangeDeviceViewController alloc] init];
  913. nextVC.isRootVCType = YES;
  914. BaseNavigationController *nextNav = [[BaseNavigationController alloc] initWithRootViewController:nextVC];
  915. self.window.rootViewController = nextNav;
  916. }
  917. #pragma mark 扫码切换设备点击返回
  918. - (void)scanChangeDeviceBackFun:(NSNotification*)not
  919. {
  920. // if(_preRootPlayerNav)
  921. // {
  922. // self.window.rootViewController = _preRootPlayerNav;
  923. // }
  924. // else{
  925. [self enterMainVCFromScene];
  926. //}
  927. [self showCalculatorVC];
  928. }
  929. #pragma mark 网络异常弹框
  930. -(void)showNetErrorAlertFun
  931. {
  932. NSInteger maskModel = [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  933. if(maskModel !=0 && ksharedAppDelegate.isDidShowPwdType){
  934. return;
  935. }
  936. NSString *linkErrTip = NSLocalizedString(@"player_link_fail_tip_type9",nil);
  937. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable){
  938. //linkErrTip = NSLocalizedString(@"player_link_fail_phone_Tips",nil);
  939. _isNeedToStopWork = YES;
  940. [self showNetErrorAlertType2Fun];
  941. return;
  942. }
  943. linkErrTip = [[NSString alloc] initWithFormat:@"[9]%@",linkErrTip];
  944. ComontAlretViewController *linkFailAlretVC= [[ComontAlretViewController alloc] initWithTiTle:nil
  945. msg:linkErrTip
  946. imageStr:nil
  947. cancelTitle:NSLocalizedString(@"single_sign_on_exit",nil)
  948. okTitle:NSLocalizedString(@"player_link_fail_tryAgain",nil) isOkBtnHighlight:YES
  949. didClickOk:^{
  950. //[self enterMainVCFromScene];
  951. } didClickCancel:^{
  952. exit(0);
  953. }];
  954. linkFailAlretVC.modalPresentationStyle = UIModalPresentationCustom;
  955. [self.window.rootViewController presentViewController:linkFailAlretVC animated:YES completion:^{
  956. linkFailAlretVC.view.superview.backgroundColor = [UIColor clearColor];
  957. }];
  958. }
  959. #pragma mark 网络异常弹框
  960. -(void)showNetErrorAlertType2Fun
  961. {
  962. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable){
  963. NSString * linkErrTip = NSLocalizedString(@"netWork_error_tip_content",nil);
  964. ComontAlretViewController *linkFailAlretVC= [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"netWork_error_tip_title",nil)
  965. msg:linkErrTip
  966. imageStr:nil
  967. cancelTitle:NSLocalizedString(@"single_sign_on_exit",nil)
  968. okTitle:nil isOkBtnHighlight:NO
  969. didClickOk:^{
  970. //[self enterMainVCFromScene];
  971. } didClickCancel:^{
  972. exit(0);
  973. }];
  974. linkFailAlretVC.modalPresentationStyle = UIModalPresentationCustom;
  975. self.window.rootViewController = [UIViewController new];
  976. [self.window.rootViewController presentViewController:linkFailAlretVC animated:YES completion:^{
  977. linkFailAlretVC.view.superview.backgroundColor = [UIColor clearColor];
  978. }];
  979. }
  980. }
  981. - (void)gotoScanAginByThridMsgErrorFun:(NSInteger)errorCode
  982. {
  983. /*扫码界面*/
  984. TipsQRCodeViewController *qrCodeVC = [[TipsQRCodeViewController alloc] init];
  985. qrCodeVC.isNeedToShowAleatType = YES;
  986. qrCodeVC.getSNMsgcode = errorCode;
  987. BaseNavigationController *qrCodeVCNav = [[BaseNavigationController alloc] initWithRootViewController:qrCodeVC];
  988. self.window.rootViewController = qrCodeVCNav;
  989. }
  990. #pragma mark 分享页面唤醒APP
  991. - (void)shareAwakenAppBy:(NSString*)shareStr
  992. {
  993. //[[iToast makeText:shareStr] show];
  994. NSArray * paraArr = [shareStr componentsSeparatedByString:@"&"];
  995. if(!paraArr || paraArr.count==0){
  996. return;
  997. }
  998. //type=save和download
  999. NSString *type = nil;
  1000. NSString *fileIds = nil;
  1001. NSString *extractionCode = nil;
  1002. NSString *token = nil;
  1003. for (NSString*objectStr in paraArr) {
  1004. if([objectStr rangeOfString:@"type"].location != NSNotFound){
  1005. NSArray * objectArr = [objectStr componentsSeparatedByString:@"="];
  1006. if(objectArr.count == 2){
  1007. type = objectArr.lastObject;
  1008. continue;
  1009. }
  1010. }
  1011. else if([objectStr rangeOfString:@"fileIds"].location != NSNotFound){
  1012. NSArray * objectArr = [objectStr componentsSeparatedByString:@"="];
  1013. if(objectArr.count == 2){
  1014. fileIds = objectArr.lastObject;
  1015. continue;
  1016. }
  1017. }
  1018. else if([objectStr rangeOfString:@"extractionCode"].location != NSNotFound){
  1019. NSArray * objectArr = [objectStr componentsSeparatedByString:@"="];
  1020. if(objectArr.count == 2){
  1021. extractionCode = objectArr.lastObject;
  1022. continue;
  1023. }
  1024. }
  1025. else if([objectStr rangeOfString:@"token"].location != NSNotFound){
  1026. NSArray * objectArr = [objectStr componentsSeparatedByString:@"="];
  1027. if(objectArr.count == 2){
  1028. token = objectArr.lastObject;
  1029. continue;
  1030. }
  1031. }
  1032. }
  1033. if(!type || type.length ==0){
  1034. HLog(@"分享 type 获取错误");
  1035. return;
  1036. }
  1037. if(!fileIds || fileIds.length ==0){
  1038. HLog(@"分享 fileIds 获取错误");
  1039. return;
  1040. }
  1041. if(!token || token.length ==0){
  1042. HLog(@"分享 token 获取错误");
  1043. return;
  1044. }
  1045. [self getShareOneFileListFunByToken:token withFileIds:fileIds withExtractionCode:extractionCode withType:type];
  1046. }
  1047. #pragma mark 分享信息重新获取
  1048. - (void)getShareOneFileListFunByToken:(NSString*)token withFileIds:(NSString*)fileIds withExtractionCode:(NSString*)extractionCode withType:(NSString*)type
  1049. {
  1050. NSMutableDictionary*paraDict = [NSMutableDictionary new];
  1051. fileIds = [fileIds stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  1052. NSData *jsonData = [fileIds dataUsingEncoding:NSUTF8StringEncoding];;
  1053. NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
  1054. HLog(@"jsonArray:%@",jsonArray)
  1055. if(!jsonArray){
  1056. return;
  1057. }
  1058. [paraDict setValue:token forKey:@"token"];
  1059. [paraDict setValue:jsonArray forKey:@"fileIdList"];
  1060. [paraDict setValue:extractionCode forKey:@"extractionCode"];
  1061. KWeakSelf
  1062. [[netWorkManager shareInstance] CommonPostCallBackCode:queryOneShareInfoFun Parameters:paraDict success:^(id _Nonnull responseObject) {
  1063. queryOneShareModel*model = [[queryOneShareModel alloc] initWithDictionary:responseObject error:nil];
  1064. if(model && model.status == 0){
  1065. weakSelf.getShareStr = nil;
  1066. [weakSelf gotoVCByModel:model withType:type];
  1067. }
  1068. else{
  1069. }
  1070. } failure:^(NSError * _Nonnull error) {
  1071. }];
  1072. }
  1073. #pragma mark 跳转
  1074. - (void)gotoVCByModel:(queryOneShareModel*)model withType:(NSString*)type
  1075. {
  1076. if([type isEqualToString:@"save"]){
  1077. [self saveFileToBoxFunBy:model];
  1078. //数据埋点
  1079. [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Share_save"];
  1080. }
  1081. else if([type isEqualToString:@"download"]){
  1082. [self downloadFileToAppFunBy:model];
  1083. //数据埋点
  1084. [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Share_download"];
  1085. }
  1086. }
  1087. #pragma mark 保存文件到盒子
  1088. - (void)saveFileToBoxFunBy:(queryOneShareModel*)sharemodel
  1089. {
  1090. NSMutableDictionary*paraDict = [NSMutableDictionary new];
  1091. NSMutableArray *pathArr = [NSMutableArray new];
  1092. for (ShareFileDataModel*dataModel in sharemodel.data.fileListVOS){
  1093. [pathArr addObject:dataModel.fileUrl];
  1094. }
  1095. if (pathArr) {
  1096. NSString *jsonStr = [iTools toJsonStrWithArray:pathArr];
  1097. if(jsonStr){
  1098. [paraDict setValue:jsonStr forKey:@"urls"];
  1099. }
  1100. }
  1101. NSString * boxSaveDefaultPath = [HWDataManager getStringWithKey:stringKeyAddSn(Const_box_save_default_path)];
  1102. if(!boxSaveDefaultPath || boxSaveDefaultPath.length == 0){
  1103. boxSaveDefaultPath = Const_default_save_path;
  1104. [HWDataManager setStringWithKey:stringKeyAddSn(Const_box_save_default_path) value:boxSaveDefaultPath];
  1105. }
  1106. [paraDict setValue:boxSaveDefaultPath forKey:@"savePath"];
  1107. KWeakSelf
  1108. [[netWorkManager shareInstance] cloudPhoneGETCallBackCode:@"downFiles" Parameters:paraDict success:^(id _Nonnull responseObject) {
  1109. SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
  1110. if(model && model.status == 0){
  1111. [weakSelf gotoUploadFileRecordVCFunByType:2 withModel:sharemodel];
  1112. }
  1113. } failure:^(NSError * _Nonnull error) {
  1114. }];
  1115. }
  1116. #pragma mark 下载文件到手机
  1117. - (void)downloadFileToAppFunBy:(queryOneShareModel*)sharemodel
  1118. {
  1119. [self gotoUploadFileRecordVCFunByType:1 withModel:sharemodel];
  1120. }
  1121. #pragma mark 跳转传输列表
  1122. - (void)gotoUploadFileRecordVCFunByType:(NSInteger)type withModel:(queryOneShareModel*)sharemodel
  1123. {
  1124. KWeakSelf
  1125. if(type == 2){
  1126. [[boxSaveFileManager shareInstance] addBoxSaveRecordFunBy:sharemodel.data.fileListVOS complete:^(BOOL isSuccess) {
  1127. if(isSuccess){
  1128. mainBlock(^{
  1129. [weakSelf gotoUploadFileRecordVCFunByType:type];
  1130. });
  1131. }
  1132. }];
  1133. }
  1134. else if (type == 1){
  1135. if(![iTools checkFreeDiskSpaceInBytesIsOK:500*1024*1024]){
  1136. mainBlock(^{
  1137. [[iToast makeText:NSLocalizedString(@"phone_space_Insufficient",nil)] show];
  1138. });
  1139. return;
  1140. }
  1141. [[boxDownloadFileManager shareInstance] addBoxDownloadRecordFunBy:sharemodel.data.fileListVOS complete:^(BOOL isSuccess) {
  1142. if(isSuccess){
  1143. mainBlock(^{
  1144. [weakSelf gotoUploadFileRecordVCFunByType:type];
  1145. });
  1146. }
  1147. }];
  1148. }
  1149. }
  1150. - (void)gotoUploadFileRecordVCFunByType:(NSInteger)type
  1151. {
  1152. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  1153. vc.isReceiveType = type;
  1154. BaseNavigationController*mainNav = ksharedAppDelegate.mainTabBar.selectedViewController;
  1155. if([mainNav isKindOfClass:[BaseNavigationController class]]){
  1156. [mainNav pushViewController:vc animated:YES];
  1157. [[UIApplication sharedApplication] setStatusBarHidden:NO];
  1158. }
  1159. }
  1160. #pragma mark UITabBarControllerDelegate
  1161. - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
  1162. {
  1163. NSInteger index = tabBarController.selectedIndex;
  1164. int eventType = 1;
  1165. NSString* eventValue = @"Nas";
  1166. if(index == 0){
  1167. eventValue = @"Nas";
  1168. }
  1169. else if(index == 1){
  1170. eventValue = @"Cloud";
  1171. }
  1172. else if(index == 2){
  1173. eventValue = @"Home";
  1174. }
  1175. //数据埋点
  1176. [[netWorkManager shareInstance] DataEmbeddingPointBy:eventType withEventValue:eventValue];
  1177. }
  1178. - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
  1179. {
  1180. if(ksharedAppDelegate.isCloudPhoneModeNotPrivacyModeOpenType
  1181. || ksharedAppDelegate.isCloudPhoneModeAndPrivacyModeOpenType){
  1182. return NO;
  1183. }
  1184. return YES;
  1185. }
  1186. @end