SceneDelegate.m 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364
  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, copy) NSString *getShareStr;//拿到分享的字符串
  59. @property (nonatomic, assign) BOOL isFirstOpenInLaunch;//启动页停两秒
  60. //冷启动分享跳入用
  61. @property(nonatomic, strong) UISceneSession *session;
  62. @property(nonatomic, strong) UISceneConnectionOptions *connectionOptions;
  63. @end
  64. @implementation SceneDelegate
  65. - (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions API_AVAILABLE(ios(13.0)){
  66. HLog(@"willConnectToSession")
  67. if (scene) {
  68. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(guideOk:) name:GuideOkNotification object:nil];
  69. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showLockViewFun:) name:lockBypwdNotification object:nil];
  70. //[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setPwdVCFun:) name:setPwdNotification object:nil];
  71. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(forgetPwdFun:) name:forgetPwdNotification object:nil];
  72. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(forgetPwdBackFun:) name:forgetPwdBackNotification object:nil];
  73. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(forgetPwdDidSetPwdFun:) name:forgetPwdDidSetNotification object:nil];
  74. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scanChangeDeviceFun:) name:scanChangeDeviceNotification object:nil];
  75. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scanChangeDeviceBackFun:) name:scanChangeDeviceBackNotification object:nil];
  76. UIWindowScene *windowScene = (UIWindowScene *)scene;
  77. self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
  78. self.window.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
  79. _isFirstOpenInLaunch = YES;
  80. // 初始化数据库
  81. [self initBrowserWindow];
  82. // 加载主页面
  83. [self enterMainVCFromScene];
  84. //
  85. [self reportVersionInfoFun];
  86. [self.window makeKeyAndVisible];
  87. ksharedAppDelegate.window = self.window;
  88. //冷启动
  89. if(connectionOptions.URLContexts != nil){
  90. _session = session;
  91. _connectionOptions = connectionOptions;
  92. // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  93. // mainBlock(^{
  94. // [self scene:scene openURLContexts:connectionOptions.URLContexts];
  95. // });
  96. // });
  97. }
  98. }
  99. }
  100. /** 主界面 - 内部使用 */
  101. - (void)enterMainVCFromScene {
  102. // ConnectTestViewController *qrCodeVCNav = [[ConnectTestViewController alloc] init];
  103. // self.window.rootViewController = qrCodeVCNav;
  104. // return;/*临时测试*/
  105. if(_isNeedToStopWork){
  106. return;
  107. }
  108. /*先判断本地有无设备 无设备时需要先扫码添加设备*/
  109. NSDictionary *deviceDict = [HWDataManager getObjectWithKey:Const_Have_Add_Device];
  110. if (!deviceDict || ![[deviceDict allKeys] containsObject:Const_Have_Add_Device_SN]){
  111. //默认显示最近文件
  112. [HWDataManager setBoolWithKey:Const_last_file_show value:YES];
  113. /*扫码界面*/
  114. TipsQRCodeViewController *qrCodeVC = [[TipsQRCodeViewController alloc] init];
  115. BaseNavigationController *qrCodeVCNav = [[BaseNavigationController alloc] initWithRootViewController:qrCodeVC];
  116. self.window.rootViewController = qrCodeVCNav;
  117. _isQRCodeType = YES;
  118. return;
  119. }
  120. NSString *SNStr = deviceDict[@"Const_Have_Add_Device_SN"];
  121. // GuideViewController
  122. BOOL haveGuide = [HWDataManager getBoolWithKey:Const_Have_Show_Guide];
  123. if (haveGuide) {
  124. ;
  125. }else {
  126. GuideViewController *guiDeVC = [[GuideViewController alloc] init];
  127. guiDeVC.delegate = self;
  128. guiDeVC.sn = SNStr;
  129. self.window.rootViewController = guiDeVC;
  130. return;
  131. }
  132. //BOOL haveOpenMask = [HWDataManager getBoolWithKey:Const_Mask_View_Open];
  133. #ifdef developJSQ
  134. NSInteger maskModel = 1;// [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  135. #else
  136. NSInteger maskModel = [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  137. #endif
  138. //添加默认启动图片
  139. if(!_customLaunchV && maskModel == 0){
  140. _customLaunchV = [[customLaunchView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H)];
  141. [self.window addSubview:_customLaunchV];
  142. }
  143. if(maskModel == 0 && _isFirstOpenInLaunch){
  144. //20240612 产品觉得 启动页太快了 要停两秒
  145. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  146. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable)
  147. {
  148. [[iToast makeText:NSLocalizedString(@"phone_network_fail_Tips",nil)] show];
  149. customToastVew *toastview = [customToastVew makeText:NSLocalizedString(@"phone_network_fail_Tips",nil)];
  150. [toastview show];
  151. [self->_customLaunchV addSubview:toastview];
  152. return;
  153. }
  154. [self getDeviceMsgInMainVCWith:deviceDict];
  155. });
  156. _isFirstOpenInLaunch = NO;
  157. }
  158. else{
  159. //延时等网络状态
  160. if(_isFirstOpenInLaunch){
  161. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  162. [self getDeviceMsgInMainVCWith:deviceDict];
  163. });
  164. _isFirstOpenInLaunch = NO;
  165. }
  166. else{
  167. [self getDeviceMsgInMainVCWith:deviceDict];
  168. }
  169. }
  170. //[self showNetErrorAlertType2Fun];
  171. }
  172. - (void)getDeviceMsgInMainVCWith:(NSDictionary*)deviceDict
  173. {
  174. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable)
  175. {
  176. BOOL isPrivacyMode = [HWDataManager getBoolWithKey:Const_Have_Add_Device_Privacy_Mode];
  177. NSInteger maskModel = [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  178. if(!isPrivacyMode && maskModel == 0){
  179. return;
  180. }
  181. [self initMainTabbarFun];
  182. [self showCalculatorVC];
  183. return;
  184. }
  185. KWeakSelf
  186. //有设备了先去做链接准备 // 80bec9c5
  187. NSString *SNStr = deviceDict[@"Const_Have_Add_Device_SN"];
  188. NSString *sdnId = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.sdnId;
  189. if(SNStr && !sdnId){
  190. [[connectDeviceManager shareInstance] getThridMsgBySN:SNStr needReconnect:YES didNetEnd:^(NSInteger didSuc) {
  191. if(didSuc == 0){
  192. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  193. mainBlock(^{
  194. [weakSelf showNetErrorAlertFun];
  195. [weakSelf enterMainVCFromSceneSecondStepFun];
  196. });
  197. });
  198. }
  199. else if(didSuc == 2
  200. ||didSuc == 201
  201. ||didSuc == 202){
  202. [weakSelf gotoScanAginByThridMsgErrorFun:didSuc];
  203. }
  204. else{
  205. [weakSelf enterMainVCFromSceneSecondStepFun];
  206. }
  207. }];
  208. }
  209. else{
  210. [self enterMainVCFromSceneSecondStepFun];
  211. }
  212. }
  213. - (void)enterMainVCFromSceneSecondStepFun
  214. {
  215. //确保通过SN号拿到密码了
  216. //非扫码进入 进入到这里很可能还没联网拿到设备最新信息
  217. if(![connectDeviceManager shareInstance].DeviceThirdIdMod){
  218. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  219. mainBlock(^{
  220. [self enterMainVCFromScene];
  221. });
  222. });
  223. return;
  224. }
  225. //是否已经有密码了 有就是输入密码 没有就是设置密码
  226. NSString *curPwd = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.password;
  227. NSString * sdnId = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.sdnId;
  228. if(!sdnId){
  229. HLog(@"没有拿到sdnId");
  230. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  231. mainBlock(^{
  232. [self enterMainVCFromScene];
  233. });
  234. });
  235. return;
  236. }
  237. if(_customLaunchV){
  238. [_customLaunchV removeFromSuperview];
  239. _customLaunchV = nil;
  240. }
  241. if(curPwd && curPwd.length > 0){
  242. /*设置密码*/
  243. // inputPWDViewController *nextVC = [[inputPWDViewController alloc] init];
  244. // BaseNavigationController *nextVCNav = [[BaseNavigationController alloc] initWithRootViewController:nextVC];
  245. // self.window.rootViewController = nextVCNav;
  246. }
  247. else{
  248. /*没有设置密码*/
  249. SetPWDFirstViewController *qrCodeVC = [[SetPWDFirstViewController alloc] init];
  250. BaseNavigationController *qrCodeVCNav = [[BaseNavigationController alloc] initWithRootViewController:qrCodeVC];
  251. self.window.rootViewController = qrCodeVCNav;
  252. return;
  253. }
  254. //下载配置先处理
  255. [boxDownloadFileManager shareInstance];
  256. [lastFileManager shareManager].uid = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.sn;
  257. [audioPlayListManager shareManager].uid = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.sn;
  258. //获取NAS相关信息
  259. [self getNASMsgFun];
  260. [self initMainTabbarFun];
  261. self.isLoginAgainType = NO;
  262. __block BOOL isPrivacyMode = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.isPrivacyMode;
  263. //KWeakSelf
  264. if(!_isQRCodeType){
  265. if(isPrivacyMode)
  266. {
  267. [self showCalculatorVC];
  268. }
  269. else{
  270. [self HandleEnterNotPrivacyModeFun];
  271. [connectDeviceManager shareInstance].isFirstInputPwdDone = YES;
  272. //playerRootVC.isPwdVCShow = NO;
  273. //[playerRootVC setShowImgAndVoiceTypeFun:YES];
  274. //[weakSelf shareAwakenAppBy:weakSelf.getShareStr];
  275. if(self->_session && self->_connectionOptions){
  276. [self scene:self->_session openURLContexts:self->_connectionOptions.URLContexts];
  277. }
  278. }
  279. //_isQRCodeType = NO;
  280. }
  281. else{
  282. if(isPrivacyMode)
  283. {
  284. [self showCalculatorVC];
  285. }
  286. else{
  287. [[webSocketManager shareInstance] opencommandChannelManagerrc_openURL];
  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:@"#7C8196"],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([connectDeviceManager shareInstance].DeviceThirdIdMod){
  531. isPrivacyMode = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.isPrivacyMode;
  532. }
  533. if(!isPrivacyMode){
  534. return;
  535. }
  536. //修复扫描已经有密码的合作 点击跳过因为网络弹框再次覆盖一次密码(需要输入两次密码)
  537. BaseNavigationController*curTopNav = (BaseNavigationController*)[iTools appRootViewController];
  538. if([curTopNav isKindOfClass:[BaseNavigationController class]]){
  539. NSArray *vcArr = [curTopNav viewControllers];
  540. if(vcArr && vcArr.count >0){
  541. UIViewController *lastVC = vcArr.lastObject;
  542. if([lastVC isKindOfClass:[inputPWDViewController class]]){
  543. return;
  544. }
  545. }
  546. }
  547. /*无有效时长直接返回不加载任何加密界面*/
  548. NSString *PwdStr = nil;
  549. NSDictionary *deviceDict = [HWDataManager getObjectWithKey:Const_Have_Add_Device];
  550. //实时拿到的密码 (每次打开或者更换设备 通过SN重新拿)
  551. if([connectDeviceManager shareInstance].DeviceThirdIdMod.data.password){
  552. NSString *curPwd = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.password;
  553. NSString*desPwdStr = [RSATool AES128Decrypt:curPwd key:AESCODEKEEYY];
  554. if(desPwdStr){
  555. PwdStr = desPwdStr;
  556. }
  557. }
  558. else{
  559. //本地密码本地判断 密码改在服务器保持
  560. if ([[deviceDict allKeys] containsObject:Const_Have_Add_Device_PWD]){
  561. PwdStr = [deviceDict objectForKey:Const_Have_Add_Device_PWD];
  562. }
  563. }
  564. if (!PwdStr || [PwdStr isEqualToString:@""])
  565. {
  566. return;
  567. }
  568. // BOOL haveOpenMask = [HWDataManager getBoolWithKey:Const_Mask_View_Open];
  569. // if (!haveOpenMask){
  570. // //输入密码界面
  571. // [self closeCalculatorVC];
  572. // _inputVC = [[inputPWDViewController alloc] init];
  573. // [self.window addSubview:_inputVC.view];
  574. // return;
  575. // }
  576. BOOL haveVaildTime = [HWDataManager getBoolWithKey:Const_Have_No_VaildTime];
  577. if (haveVaildTime == YES){/*无有效时间*/
  578. return;
  579. }
  580. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus != AFNetworkReachabilityStatusNotReachable)
  581. {
  582. if(![connectDeviceManager shareInstance].DeviceThirdIdMod){
  583. return;
  584. }
  585. BOOL isPrivacyMode = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.isPrivacyMode;
  586. if(!isPrivacyMode)
  587. {
  588. [connectDeviceManager shareInstance].isFirstInputPwdDone = YES;
  589. [[NSNotificationCenter defaultCenter] postNotificationName:didInputPWDNotification object:nil];
  590. return;
  591. }
  592. }
  593. #ifdef developJSQ
  594. NSInteger maskModel = 1;// [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  595. #else
  596. NSInteger maskModel = [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  597. #endif
  598. if (maskModel == 0){
  599. //输入密码界面
  600. [self closeCalculatorVC];
  601. _inputVC = [[inputPWDViewController alloc] init];
  602. [self.window addSubview:_inputVC.view];
  603. ksharedAppDelegate.isDidShowPwdType = YES;
  604. }
  605. else if (maskModel == 2){
  606. /*浏览器*/
  607. [self closeCalculatorVC];
  608. _webVC = [[HWWebViewController alloc] init];
  609. _webVC.pwd = PwdStr;
  610. _webVC.webUrl = @"https://baidu.com";
  611. [self.window addSubview:_webVC.view];
  612. ksharedAppDelegate.isDidShowPwdType = YES;
  613. }else{
  614. /*计算器*/
  615. [self closeCalculatorVC];
  616. _calculatorVC = [[CalculatorViewController alloc] init];
  617. _calculatorVC.pwd = PwdStr;
  618. [self.window addSubview:_calculatorVC.view];
  619. ksharedAppDelegate.isDidShowPwdType = YES;
  620. }
  621. [[NSNotificationCenter defaultCenter] postNotificationName:ShowPwdVCNotification object:nil];
  622. }
  623. - (void)closeCalculatorVC{
  624. ksharedAppDelegate.getSystemPermissType = NO;
  625. if (_calculatorVC){
  626. [_calculatorVC.view removeFromSuperview];
  627. }
  628. /*浏览器*/
  629. if (_webVC){
  630. [_webVC.view removeFromSuperview];
  631. }
  632. if(_inputVC){
  633. [_inputVC.view removeFromSuperview];
  634. }
  635. ksharedAppDelegate.isDidShowPwdType = NO;
  636. if(self->_session && self->_connectionOptions){
  637. [self scene:self->_session openURLContexts:self->_connectionOptions.URLContexts];
  638. }
  639. }
  640. - (NSString *)documentPathForAccount:(NSString *)account fileFolder:(NSString *)fileFolder {
  641. NSString *path = DocumentPath;
  642. if (account.length != 0) {
  643. path = [NSString stringWithFormat:@"%@/%@/",DocumentPath,account];
  644. }
  645. if ([fileFolder containsString:@"/"]) {
  646. NSString *path1 = [path stringByAppendingPathComponent:fileFolder];
  647. path1 = [path1 stringByDeletingLastPathComponent];
  648. NSError *error;
  649. if (![[NSFileManager defaultManager] fileExistsAtPath:path1]) {
  650. [[NSFileManager defaultManager] createDirectoryAtPath:path1 withIntermediateDirectories:YES attributes:nil error:&error];
  651. }
  652. }else{
  653. NSError *error;
  654. if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
  655. [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error];
  656. }
  657. }
  658. return [path stringByAppendingPathComponent:fileFolder];
  659. }
  660. - (void)startUseBtnBePressed{
  661. [self enterMainVCFromScene];
  662. // NSString *launchAppPWDPath = [self documentPathForAccount:@"" fileFolder:@"LaunchPWD"];
  663. // NSString *str = [[NSString alloc] initWithContentsOfFile:launchAppPWDPath encoding:(NSUTF8StringEncoding) error:nil];
  664. // if (!str || [str isEqualToString:@"0"])
  665. // {
  666. // SetUsePWDViewController *loginVC = [[SetUsePWDViewController alloc] init];
  667. // loginVC.delegate = self;
  668. // self.window.rootViewController = loginVC;
  669. //
  670. // return;
  671. // }
  672. //
  673. // NSArray *dataArray = [BaseModel bg_findAll:DB_BrowserWindows_TableName];
  674. //
  675. // if (dataArray.count == 0) { // 浏览器没有窗口
  676. // // 加载首页
  677. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  678. // vc.webUrl = Const_HomeUrl;
  679. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  680. // self.window.rootViewController = nvc;
  681. //
  682. // }else {
  683. // // 浏览器当前窗口索引ID
  684. // NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  685. // NSString *where = [NSString stringWithFormat:@"where %@=%ld",bg_sqlKey(@"ID"),(long)ID];
  686. // NSArray* finfAlls = [BaseModel bg_find:DB_BrowserWindows_TableName where:where];
  687. // BaseModel *model = finfAlls.firstObject;
  688. //
  689. // // 加载网页
  690. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  691. // vc.webUrl = model.webUrl;
  692. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  693. // self.window.rootViewController = nvc;
  694. // }
  695. }
  696. - (void)loginOk{
  697. [self enterMainVCFromScene];
  698. }
  699. - (void)guideOk:(NSNotification*)not{
  700. NSString *object = not.object;
  701. if(object && [object isEqualToString:@"isLoginAgainType"]){
  702. self.isLoginAgainType = YES;
  703. }
  704. [self enterMainVCFromScene];
  705. //clear下载和上传的已经获取的数据
  706. [[uploadFileManager shareInstance] suspendUploadFileFun:YES withModel:nil];
  707. [uploadFileManager shareInstance].databaseArr = [NSMutableArray new];
  708. [uploadFileManager shareInstance].fileModelDataArr = [NSMutableArray new];
  709. [uploadFileManager shareInstance].curUploadFileDataModel.curUploadStateType = uploadStateWait;
  710. [[downloadManager shareInstance] suspendDownloadFileFun:YES withModel:nil];
  711. [downloadManager shareInstance].databaseArr = [NSMutableArray new];
  712. [downloadManager shareInstance].downLoadFileModelDataArr = [NSMutableArray new];
  713. [[backupsFileManager shareInstance] suspendBackupsFileFun];
  714. //frp的下载
  715. [[customDownloadManager shareManager] suspendAllDownloadTask];
  716. NSString *uid =[connectDeviceManager shareInstance].DeviceThirdIdMod.data.sn;
  717. if(uid){
  718. }
  719. else{
  720. uid = @"";
  721. }
  722. [customDownloadManager shareManager].uid = uid;
  723. //盒子1音频在播放音乐,切换盒子2成功,仍在播放中
  724. [[DFPlayer sharedPlayer] df_deallocPlayer];
  725. [lastFileManager shareManager].uid = uid;
  726. [audioPlayListManager shareManager].uid = uid;
  727. }
  728. #pragma mark 上报版本号信息
  729. -(void)reportVersionInfoFun
  730. {
  731. NSMutableDictionary *paraDict = [NSMutableDictionary new];
  732. NSString *vers = [iPhone appVersion];
  733. if(vers){
  734. [paraDict setValue:vers forKey:@"iosClientVersionNumber"];
  735. }
  736. NSDictionary *deviceDict = [HWDataManager getObjectWithKey:Const_Have_Add_Device];
  737. if (deviceDict && [[deviceDict allKeys] containsObject:Const_Have_Add_Device_SN]){
  738. NSString*snStr = deviceDict[Const_Have_Add_Device_SN];
  739. if(snStr){
  740. [paraDict setValue:snStr forKey:@"sn"];
  741. }
  742. else{
  743. return;
  744. }
  745. }
  746. else{
  747. return;;
  748. }
  749. // KWeakSelf
  750. [[netWorkManager shareInstance] CommonPostCallBackCode:reportVersionInfo Parameters:paraDict success:^(id _Nonnull responseObject) {
  751. } failure:^(NSError * _Nonnull error) {
  752. }];
  753. }
  754. #pragma mark 获取NAS相关信息
  755. -(void)getNASMsgFun
  756. {
  757. NSMutableDictionary *paraDict = [NSMutableDictionary new];
  758. NSString *SNStr = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.changeSn;
  759. if(SNStr){
  760. [paraDict setValue:SNStr forKey:@"sn"];
  761. }
  762. else{
  763. return;;
  764. }
  765. KWeakSelf
  766. [[netWorkManager shareInstance] CommonGetWithCallBackCode:getIpFun Parameters:paraDict success:^(id _Nonnull responseObject){
  767. NASMsgModel *model = [[NASMsgModel alloc] initWithDictionary:responseObject error:nil];
  768. if(model){
  769. ksharedAppDelegate.NASMsgMod = model;
  770. }
  771. } failure:^(NSError * _Nonnull error) {
  772. }];
  773. }
  774. #pragma mark 主动上锁
  775. - (void)showLockViewFun:(NSNotification*)not
  776. {
  777. [self showCalculatorVC];
  778. }
  779. #pragma mark 进入设置密码
  780. //- (void)setPwdVCFun:(NSNotification*)not
  781. //{
  782. // _isNeedToShowSecretKey = YES;
  783. //}
  784. #pragma mark 忘记密码
  785. - (void)forgetPwdFun:(NSNotification*)not
  786. {
  787. /*忘记密码*/
  788. forgetPwdViewController *forgetPwdVC = [[forgetPwdViewController alloc] init];
  789. BaseNavigationController *forgetPwdVCNav = [[BaseNavigationController alloc] initWithRootViewController:forgetPwdVC];
  790. self.window.rootViewController = forgetPwdVCNav;
  791. }
  792. #pragma mark 忘记密码返回
  793. - (void)forgetPwdBackFun:(NSNotification*)not
  794. {
  795. // if(_preRootPlayerNav)
  796. // {
  797. // self.window.rootViewController = _preRootPlayerNav;
  798. // }
  799. // else{
  800. [self enterMainVCFromScene];
  801. //}
  802. [self showCalculatorVC];
  803. }
  804. #pragma mark 忘记密码设置密码完成
  805. - (void)forgetPwdDidSetPwdFun:(NSNotification*)not
  806. {
  807. // if(_preRootPlayerNav)
  808. // {
  809. // NSArray *vcArr = _preRootPlayerNav.viewControllers;
  810. // if(vcArr.count > 2){
  811. // [_preRootPlayerNav popToViewController:vcArr[1] animated:NO];
  812. // }
  813. // self.window.rootViewController = _preRootPlayerNav;
  814. // }
  815. // else{
  816. [self enterMainVCFromScene];
  817. //}
  818. [self closeCalculatorVC];
  819. [connectDeviceManager shareInstance].isFirstInputPwdDone = YES;
  820. }
  821. #pragma mark 扫码切换设备 scanChangeDeviceNotification
  822. - (void)scanChangeDeviceFun:(NSNotification*)not
  823. {
  824. //TipsQRCodeForChangeDeviceViewController *nextVC = [[TipsQRCodeForChangeDeviceViewController alloc] init];
  825. QRCodeScanForChangeDeviceViewController *nextVC = [[QRCodeScanForChangeDeviceViewController alloc] init];
  826. nextVC.isRootVCType = YES;
  827. BaseNavigationController *nextNav = [[BaseNavigationController alloc] initWithRootViewController:nextVC];
  828. self.window.rootViewController = nextNav;
  829. }
  830. #pragma mark 扫码切换设备点击返回
  831. - (void)scanChangeDeviceBackFun:(NSNotification*)not
  832. {
  833. // if(_preRootPlayerNav)
  834. // {
  835. // self.window.rootViewController = _preRootPlayerNav;
  836. // }
  837. // else{
  838. [self enterMainVCFromScene];
  839. //}
  840. [self showCalculatorVC];
  841. }
  842. #pragma mark 网络异常弹框
  843. -(void)showNetErrorAlertFun
  844. {
  845. NSInteger maskModel = [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  846. if(maskModel !=0 && ksharedAppDelegate.isDidShowPwdType){
  847. return;
  848. }
  849. NSString *linkErrTip = NSLocalizedString(@"player_link_fail_tip_type9",nil);
  850. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable){
  851. linkErrTip = NSLocalizedString(@"player_link_fail_phone_Tips",nil);
  852. _isNeedToStopWork = YES;
  853. [self showNetErrorAlertType2Fun];
  854. return;
  855. }
  856. linkErrTip = [[NSString alloc] initWithFormat:@"[9]%@",linkErrTip];
  857. ComontAlretViewController *linkFailAlretVC= [[ComontAlretViewController alloc] initWithTiTle:nil
  858. msg:linkErrTip
  859. imageStr:nil
  860. cancelTitle:NSLocalizedString(@"single_sign_on_exit",nil)
  861. okTitle:NSLocalizedString(@"player_link_fail_tryAgain",nil) isOkBtnHighlight:YES
  862. didClickOk:^{
  863. //[self enterMainVCFromScene];
  864. } didClickCancel:^{
  865. exit(0);
  866. }];
  867. linkFailAlretVC.modalPresentationStyle = UIModalPresentationCustom;
  868. [self.window.rootViewController presentViewController:linkFailAlretVC animated:YES completion:^{
  869. linkFailAlretVC.view.superview.backgroundColor = [UIColor clearColor];
  870. }];
  871. }
  872. #pragma mark 网络异常弹框
  873. -(void)showNetErrorAlertType2Fun
  874. {
  875. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable){
  876. NSString * linkErrTip = NSLocalizedString(@"netWork_error_tip_content",nil);
  877. ComontAlretViewController *linkFailAlretVC= [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"netWork_error_tip_title",nil)
  878. msg:linkErrTip
  879. imageStr:nil
  880. cancelTitle:NSLocalizedString(@"single_sign_on_exit",nil)
  881. okTitle:nil isOkBtnHighlight:NO
  882. didClickOk:^{
  883. //[self enterMainVCFromScene];
  884. } didClickCancel:^{
  885. exit(0);
  886. }];
  887. linkFailAlretVC.modalPresentationStyle = UIModalPresentationCustom;
  888. self.window.rootViewController = [UIViewController new];
  889. [self.window.rootViewController presentViewController:linkFailAlretVC animated:YES completion:^{
  890. linkFailAlretVC.view.superview.backgroundColor = [UIColor clearColor];
  891. }];
  892. }
  893. }
  894. - (void)gotoScanAginByThridMsgErrorFun:(NSInteger)errorCode
  895. {
  896. /*扫码界面*/
  897. TipsQRCodeViewController *qrCodeVC = [[TipsQRCodeViewController alloc] init];
  898. qrCodeVC.isNeedToShowAleatType = YES;
  899. qrCodeVC.getSNMsgcode = errorCode;
  900. BaseNavigationController *qrCodeVCNav = [[BaseNavigationController alloc] initWithRootViewController:qrCodeVC];
  901. self.window.rootViewController = qrCodeVCNav;
  902. }
  903. #pragma mark 分享页面唤醒APP
  904. - (void)shareAwakenAppBy:(NSString*)shareStr
  905. {
  906. //[[iToast makeText:shareStr] show];
  907. NSArray * paraArr = [shareStr componentsSeparatedByString:@"&"];
  908. if(!paraArr || paraArr.count==0){
  909. return;
  910. }
  911. //type=save和download
  912. NSString *type = nil;
  913. NSString *fileIds = nil;
  914. NSString *extractionCode = nil;
  915. NSString *token = nil;
  916. for (NSString*objectStr in paraArr) {
  917. if([objectStr rangeOfString:@"type"].location != NSNotFound){
  918. NSArray * objectArr = [objectStr componentsSeparatedByString:@"="];
  919. if(objectArr.count == 2){
  920. type = objectArr.lastObject;
  921. continue;
  922. }
  923. }
  924. else if([objectStr rangeOfString:@"fileIds"].location != NSNotFound){
  925. NSArray * objectArr = [objectStr componentsSeparatedByString:@"="];
  926. if(objectArr.count == 2){
  927. fileIds = objectArr.lastObject;
  928. continue;
  929. }
  930. }
  931. else if([objectStr rangeOfString:@"extractionCode"].location != NSNotFound){
  932. NSArray * objectArr = [objectStr componentsSeparatedByString:@"="];
  933. if(objectArr.count == 2){
  934. extractionCode = objectArr.lastObject;
  935. continue;
  936. }
  937. }
  938. else if([objectStr rangeOfString:@"token"].location != NSNotFound){
  939. NSArray * objectArr = [objectStr componentsSeparatedByString:@"="];
  940. if(objectArr.count == 2){
  941. token = objectArr.lastObject;
  942. continue;
  943. }
  944. }
  945. }
  946. if(!type || type.length ==0){
  947. HLog(@"分享 type 获取错误");
  948. return;
  949. }
  950. if(!fileIds || fileIds.length ==0){
  951. HLog(@"分享 fileIds 获取错误");
  952. return;
  953. }
  954. if(!token || token.length ==0){
  955. HLog(@"分享 token 获取错误");
  956. return;
  957. }
  958. [self getShareOneFileListFunByToken:token withFileIds:fileIds withExtractionCode:extractionCode withType:type];
  959. }
  960. #pragma mark 分享信息重新获取
  961. - (void)getShareOneFileListFunByToken:(NSString*)token withFileIds:(NSString*)fileIds withExtractionCode:(NSString*)extractionCode withType:(NSString*)type
  962. {
  963. NSMutableDictionary*paraDict = [NSMutableDictionary new];
  964. fileIds = [fileIds stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  965. NSData *jsonData = [fileIds dataUsingEncoding:NSUTF8StringEncoding];;
  966. NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
  967. HLog(@"jsonArray:%@",jsonArray)
  968. if(!jsonArray){
  969. return;
  970. }
  971. [paraDict setValue:token forKey:@"token"];
  972. [paraDict setValue:jsonArray forKey:@"fileIdList"];
  973. [paraDict setValue:extractionCode forKey:@"extractionCode"];
  974. KWeakSelf
  975. [[netWorkManager shareInstance] CommonPostCallBackCode:queryOneShareInfoFun Parameters:paraDict success:^(id _Nonnull responseObject) {
  976. queryOneShareModel*model = [[queryOneShareModel alloc] initWithDictionary:responseObject error:nil];
  977. if(model && model.status == 0){
  978. weakSelf.getShareStr = nil;
  979. [weakSelf gotoVCByModel:model withType:type];
  980. }
  981. else{
  982. }
  983. } failure:^(NSError * _Nonnull error) {
  984. }];
  985. }
  986. #pragma mark 跳转
  987. - (void)gotoVCByModel:(queryOneShareModel*)model withType:(NSString*)type
  988. {
  989. if([type isEqualToString:@"save"]){
  990. [self saveFileToBoxFunBy:model];
  991. //数据埋点
  992. [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Share_save"];
  993. }
  994. else if([type isEqualToString:@"download"]){
  995. [self downloadFileToAppFunBy:model];
  996. //数据埋点
  997. [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Share_download"];
  998. }
  999. }
  1000. #pragma mark 保存文件到盒子
  1001. - (void)saveFileToBoxFunBy:(queryOneShareModel*)sharemodel
  1002. {
  1003. NSMutableDictionary*paraDict = [NSMutableDictionary new];
  1004. NSMutableArray *pathArr = [NSMutableArray new];
  1005. for (ShareFileDataModel*dataModel in sharemodel.data.fileListVOS){
  1006. [pathArr addObject:dataModel.fileUrl];
  1007. }
  1008. if (pathArr) {
  1009. NSString *jsonStr = [iTools toJsonStrWithArray:pathArr];
  1010. if(jsonStr){
  1011. [paraDict setValue:jsonStr forKey:@"urls"];
  1012. }
  1013. }
  1014. NSString * boxSaveDefaultPath = [HWDataManager getStringWithKey:stringKeyAddSn(Const_box_save_default_path)];
  1015. if(!boxSaveDefaultPath || boxSaveDefaultPath.length == 0){
  1016. boxSaveDefaultPath = Const_default_save_path;
  1017. [HWDataManager setStringWithKey:stringKeyAddSn(Const_box_save_default_path) value:boxSaveDefaultPath];
  1018. }
  1019. [paraDict setValue:boxSaveDefaultPath forKey:@"savePath"];
  1020. KWeakSelf
  1021. [[netWorkManager shareInstance] cloudPhoneGETCallBackCode:@"downFiles" Parameters:paraDict success:^(id _Nonnull responseObject) {
  1022. SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
  1023. if(model && model.status == 0){
  1024. [weakSelf gotoUploadFileRecordVCFunByType:2 withModel:sharemodel];
  1025. }
  1026. } failure:^(NSError * _Nonnull error) {
  1027. }];
  1028. }
  1029. #pragma mark 下载文件到手机
  1030. - (void)downloadFileToAppFunBy:(queryOneShareModel*)sharemodel
  1031. {
  1032. [self gotoUploadFileRecordVCFunByType:1 withModel:sharemodel];
  1033. }
  1034. #pragma mark 跳转传输列表
  1035. - (void)gotoUploadFileRecordVCFunByType:(NSInteger)type withModel:(queryOneShareModel*)sharemodel
  1036. {
  1037. KWeakSelf
  1038. if(type == 2){
  1039. [[boxSaveFileManager shareInstance] addBoxSaveRecordFunBy:sharemodel.data.fileListVOS complete:^(BOOL isSuccess) {
  1040. if(isSuccess){
  1041. mainBlock(^{
  1042. [weakSelf gotoUploadFileRecordVCFunByType:type];
  1043. });
  1044. }
  1045. }];
  1046. }
  1047. else if (type == 1){
  1048. if(![iTools checkFreeDiskSpaceInBytesIsOK:500*1024*1024]){
  1049. mainBlock(^{
  1050. [[iToast makeText:NSLocalizedString(@"phone_space_Insufficient",nil)] show];
  1051. });
  1052. return;
  1053. }
  1054. [[boxDownloadFileManager shareInstance] addBoxDownloadRecordFunBy:sharemodel.data.fileListVOS complete:^(BOOL isSuccess) {
  1055. if(isSuccess){
  1056. mainBlock(^{
  1057. [weakSelf gotoUploadFileRecordVCFunByType:type];
  1058. });
  1059. }
  1060. }];
  1061. }
  1062. }
  1063. - (void)gotoUploadFileRecordVCFunByType:(NSInteger)type
  1064. {
  1065. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  1066. vc.isReceiveType = type;
  1067. BaseNavigationController*mainNav = ksharedAppDelegate.mainTabBar.selectedViewController;
  1068. if([mainNav isKindOfClass:[BaseNavigationController class]]){
  1069. [mainNav pushViewController:vc animated:YES];
  1070. [[UIApplication sharedApplication] setStatusBarHidden:NO];
  1071. }
  1072. }
  1073. #pragma mark UITabBarControllerDelegate
  1074. - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
  1075. {
  1076. NSInteger index = tabBarController.selectedIndex;
  1077. int eventType = 1;
  1078. NSString* eventValue = @"Nas";
  1079. if(index == 0){
  1080. eventValue = @"Nas";
  1081. }
  1082. else if(index == 1){
  1083. eventValue = @"Cloud";
  1084. }
  1085. else if(index == 2){
  1086. eventValue = @"Home";
  1087. }
  1088. //数据埋点
  1089. [[netWorkManager shareInstance] DataEmbeddingPointBy:eventType withEventValue:eventValue];
  1090. }
  1091. @end