SceneDelegate.m 47 KB

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