SceneDelegate.m 48 KB

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