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