SceneDelegate.m 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333
  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. @interface SceneDelegate ()<SetUsePWDViewControllerDelegate,GuideViewControllerDelegate,UITabBarControllerDelegate>
  42. @property(nonatomic, strong) CalculatorViewController *calculatorVC;
  43. @property(nonatomic, strong) HWWebViewController *webVC;
  44. @property(nonatomic, strong) inputPWDViewController *inputVC;
  45. @property(nonatomic, strong) customLaunchView *customLaunchV;//
  46. //@property(nonatomic, strong) PlayerViewController *curPlayerVC;
  47. @property(nonatomic, strong) BaseNavigationController *preRootPlayerNav;
  48. @property(nonatomic, assign) bool isQRCodeType;//第一次 扫码进来的
  49. //@property(nonatomic, assign) bool isNeedToShowSecretKey;//扫码进来的SN 没有密码 则需要显示秘钥
  50. @property (nonatomic, assign) BOOL isLoginAgainType;// 单点登录 点重新登录进来的
  51. @property (nonatomic, assign) BOOL isNeedToStopWork;// 无网络报错
  52. @property (nonatomic, assign) BOOL isDidShowPwdType;// 是否显示密码界面了
  53. @property(nonatomic, copy) NSString *getShareStr;//拿到分享的字符串
  54. //冷启动分享跳入用
  55. @property(nonatomic, strong) UISceneSession *session;
  56. @property(nonatomic, strong) UISceneConnectionOptions *connectionOptions;
  57. @end
  58. @implementation SceneDelegate
  59. - (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions API_AVAILABLE(ios(13.0)){
  60. if (scene) {
  61. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(guideOk:) name:GuideOkNotification object:nil];
  62. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showLockViewFun:) name:lockBypwdNotification object:nil];
  63. //[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setPwdVCFun:) name:setPwdNotification object:nil];
  64. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(forgetPwdFun:) name:forgetPwdNotification object:nil];
  65. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(forgetPwdBackFun:) name:forgetPwdBackNotification object:nil];
  66. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(forgetPwdDidSetPwdFun:) name:forgetPwdDidSetNotification object:nil];
  67. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scanChangeDeviceFun:) name:scanChangeDeviceNotification object:nil];
  68. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scanChangeDeviceBackFun:) name:scanChangeDeviceBackNotification object:nil];
  69. UIWindowScene *windowScene = (UIWindowScene *)scene;
  70. self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
  71. self.window.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
  72. // 初始化数据库
  73. [self initBrowserWindow];
  74. // 加载主页面
  75. [self enterMainVCFromScene];
  76. //
  77. [self reportVersionInfoFun];
  78. [self.window makeKeyAndVisible];
  79. ksharedAppDelegate.window = self.window;
  80. //冷启动
  81. if(connectionOptions.URLContexts != nil){
  82. _session = session;
  83. _connectionOptions = connectionOptions;
  84. // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  85. // mainBlock(^{
  86. // [self scene:scene openURLContexts:connectionOptions.URLContexts];
  87. // });
  88. // });
  89. }
  90. }
  91. }
  92. /** 进入登录界面 - 内部使用 */
  93. - (void)enterLoginVCFromScene {
  94. // UIViewController *vc = [[UIViewController alloc] init];
  95. // vc.view.backgroundColor = [UIColor redColor];
  96. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  97. // self.window.rootViewController = nvc;
  98. }
  99. /** 主界面 - 内部使用 */
  100. - (void)enterMainVCFromScene {
  101. // ConnectTestViewController *qrCodeVCNav = [[ConnectTestViewController alloc] init];
  102. // self.window.rootViewController = qrCodeVCNav;
  103. // return;/*临时测试*/
  104. if(_isNeedToStopWork){
  105. return;
  106. }
  107. /*先判断本地有无设备 无设备时需要先扫码添加设备*/
  108. NSDictionary *deviceDict = [HWDataManager getObjectWithKey:Const_Have_Add_Device];
  109. if (!deviceDict || ![[deviceDict allKeys] containsObject:Const_Have_Add_Device_SN]){
  110. //默认显示最近文件
  111. [HWDataManager setBoolWithKey:Const_last_file_show value:YES];
  112. /*扫码界面*/
  113. TipsQRCodeViewController *qrCodeVC = [[TipsQRCodeViewController alloc] init];
  114. BaseNavigationController *qrCodeVCNav = [[BaseNavigationController alloc] initWithRootViewController:qrCodeVC];
  115. self.window.rootViewController = qrCodeVCNav;
  116. _isQRCodeType = YES;
  117. return;
  118. }
  119. NSString *SNStr = deviceDict[@"Const_Have_Add_Device_SN"];
  120. // GuideViewController
  121. BOOL haveGuide = [HWDataManager getBoolWithKey:Const_Have_Show_Guide];
  122. if (haveGuide) {
  123. ;
  124. }else {
  125. GuideViewController *guiDeVC = [[GuideViewController alloc] init];
  126. guiDeVC.delegate = self;
  127. guiDeVC.sn = SNStr;
  128. self.window.rootViewController = guiDeVC;
  129. return;
  130. }
  131. //BOOL haveOpenMask = [HWDataManager getBoolWithKey:Const_Mask_View_Open];
  132. #ifdef developJSQ
  133. NSInteger maskModel = 1;// [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  134. #else
  135. NSInteger maskModel = [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  136. #endif
  137. //添加默认启动图片
  138. if(!_customLaunchV && maskModel == 0){
  139. _customLaunchV = [[customLaunchView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H)];
  140. [self.window addSubview:_customLaunchV];
  141. }
  142. if(maskModel == 0){
  143. //20240612 产品觉得 启动页太快了 要停两秒
  144. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  145. [self getDeviceMsgInMainVCWith:deviceDict];
  146. });
  147. }
  148. else{
  149. [self getDeviceMsgInMainVCWith:deviceDict];
  150. }
  151. //[self showNetErrorAlertType2Fun];
  152. }
  153. - (void)getDeviceMsgInMainVCWith:(NSDictionary*)deviceDict
  154. {
  155. KWeakSelf
  156. //有设备了先去做链接准备 // 80bec9c5
  157. NSString *SNStr = deviceDict[@"Const_Have_Add_Device_SN"];
  158. NSString *sdnId = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.sdnId;
  159. if(SNStr && !sdnId){
  160. [[connectDeviceManager shareInstance] getThridMsgBySN:SNStr needReconnect:YES didNetEnd:^(NSInteger didSuc) {
  161. if(didSuc == 0){
  162. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  163. mainBlock(^{
  164. [weakSelf showNetErrorAlertFun];
  165. [weakSelf enterMainVCFromSceneSecondStepFun];
  166. });
  167. });
  168. }
  169. else if(didSuc == 2
  170. ||didSuc == 201
  171. ||didSuc == 202){
  172. [weakSelf gotoScanAginByThridMsgErrorFun:didSuc];
  173. }
  174. else{
  175. [weakSelf enterMainVCFromSceneSecondStepFun];
  176. }
  177. }];
  178. }
  179. else{
  180. [self enterMainVCFromSceneSecondStepFun];
  181. }
  182. }
  183. - (void)enterMainVCFromSceneSecondStepFun
  184. {
  185. //确保通过SN号拿到密码了
  186. //非扫码进入 进入到这里很可能还没联网拿到设备最新信息
  187. if(![connectDeviceManager shareInstance].DeviceThirdIdMod){
  188. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  189. mainBlock(^{
  190. [self enterMainVCFromScene];
  191. });
  192. });
  193. return;
  194. }
  195. //是否已经有密码了 有就是输入密码 没有就是设置密码
  196. NSString *curPwd = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.password;
  197. NSString * sdnId = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.sdnId;
  198. if(!sdnId){
  199. HLog(@"没有拿到sdnId");
  200. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  201. mainBlock(^{
  202. [self enterMainVCFromScene];
  203. });
  204. });
  205. return;
  206. }
  207. if(_customLaunchV){
  208. [_customLaunchV removeFromSuperview];
  209. _customLaunchV = nil;
  210. }
  211. if(curPwd && curPwd.length > 0){
  212. /*设置密码*/
  213. // inputPWDViewController *nextVC = [[inputPWDViewController alloc] init];
  214. // BaseNavigationController *nextVCNav = [[BaseNavigationController alloc] initWithRootViewController:nextVC];
  215. // self.window.rootViewController = nextVCNav;
  216. }
  217. else{
  218. /*没有设置密码*/
  219. SetPWDFirstViewController *qrCodeVC = [[SetPWDFirstViewController alloc] init];
  220. BaseNavigationController *qrCodeVCNav = [[BaseNavigationController alloc] initWithRootViewController:qrCodeVC];
  221. self.window.rootViewController = qrCodeVCNav;
  222. return;
  223. }
  224. //下载配置先处理
  225. [boxDownloadFileManager shareInstance];
  226. [lastFileManager shareManager].uid = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.sn;
  227. //获取NAS相关信息
  228. [self getNASMsgFun];
  229. [self initMainTabbarFun];
  230. //数据埋点
  231. [[netWorkManager shareInstance] DataEmbeddingPointBy:1 withEventValue:@"Nas"];
  232. return;
  233. // if(_curPlayerVC){
  234. // //[_curPlayerVC disconnectVideoServer];
  235. //
  236. // _curPlayerVC.isNeedRecyclResource = YES;
  237. // [_curPlayerVC recyclResource];
  238. //
  239. // _curPlayerVC.liveStreamManager = nil;
  240. // [_curPlayerVC.navigationController popViewControllerAnimated:NO];
  241. // _curPlayerVC = nil;
  242. // }
  243. //
  244. // //每次进入
  245. // PlayerViewController *playerRootVC = [[PlayerViewController alloc] init];
  246. // if(self.isLoginAgainType){
  247. // playerRootVC.isLoginAgainType = self.isLoginAgainType;
  248. // }
  249. // playerRootVC.isPwdVCShow = YES;
  250. // _curPlayerVC = playerRootVC;
  251. //
  252. //// BaseNavigationController *playerNav = [[BaseNavigationController alloc] initWithRootViewController:playerRootVC];
  253. //// self.window.rootViewController = playerNav;
  254. //
  255. // UIViewController *vc = [UIViewController new];
  256. //
  257. // BaseNavigationController *playerNav = [[BaseNavigationController alloc] initWithRootViewController:vc];
  258. // [playerNav pushViewController:playerRootVC animated:NO];
  259. // self.window.rootViewController = playerNav;
  260. //
  261. // _preRootPlayerNav = playerNav;
  262. //
  263. // self.isLoginAgainType = NO;
  264. //
  265. // __block BOOL isPrivacyMode = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.isPrivacyMode;
  266. //
  267. // KWeakSelf
  268. // if(!_isQRCodeType){
  269. //
  270. // if(isPrivacyMode)
  271. // {
  272. // [playerRootVC setShowImgAndVoiceTypeFun:NO];
  273. // [self showCalculatorVC];
  274. // }
  275. // else{
  276. // [self HandleEnterNotPrivacyModeFun];
  277. //
  278. // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  279. // mainBlock(^{
  280. // [connectDeviceManager shareInstance].isFirstInputPwdDone = YES;
  281. // playerRootVC.isPwdVCShow = NO;
  282. // [playerRootVC setShowImgAndVoiceTypeFun:YES];
  283. // //[weakSelf shareAwakenAppBy:weakSelf.getShareStr];
  284. //
  285. // if(self->_session && self->_connectionOptions){
  286. // [self scene:self->_session openURLContexts:self->_connectionOptions.URLContexts];
  287. // }
  288. // });
  289. // });
  290. // }
  291. //
  292. // //_isQRCodeType = NO;
  293. // }
  294. // else{
  295. // if(isPrivacyMode)
  296. // {
  297. // [playerRootVC setShowImgAndVoiceTypeFun:NO];
  298. // [self showCalculatorVC];
  299. // }
  300. // else{
  301. // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  302. // mainBlock(^{
  303. // playerRootVC.isPwdVCShow = NO;
  304. // [playerRootVC setShowImgAndVoiceTypeFun:YES];
  305. // });
  306. // });
  307. // }
  308. //
  309. // }
  310. //
  311. // _isQRCodeType = NO;
  312. //
  313. // //获取NAS相关信息
  314. // [self getNASMsgFun];
  315. //
  316. // [self initMainTabbarFun];
  317. }
  318. #pragma mark 1.4.1 新增tabbar
  319. - (void)initMainTabbarFun
  320. {
  321. UITabBarController *tabBarController = [[UITabBarController alloc] init];
  322. tabBarController.delegate = self;
  323. NASViewController *NASVC = [[NASViewController alloc] init];
  324. BaseNavigationController *NasNav = [[BaseNavigationController alloc] initWithRootViewController:NASVC];
  325. cloudPhoneViewController *cloudVC = [[cloudPhoneViewController alloc] init];
  326. BaseNavigationController *cloudPhoneNav = [[BaseNavigationController alloc] initWithRootViewController:cloudVC];
  327. mineViewController *mineVC = [[mineViewController alloc] init];
  328. BaseNavigationController *mineNav = [[BaseNavigationController alloc] initWithRootViewController:mineVC];
  329. NSArray *viewControllers = @[NasNav, cloudPhoneNav,mineNav]; // 添加更多视图控制器
  330. tabBarController.viewControllers = viewControllers;
  331. NSString*phoneTitle = NSLocalizedString(@"tabbar_cloud_phone",nil);
  332. NSString*myTitle = NSLocalizedString(@"tabbar_my_title",nil);
  333. NSArray *titleArr = @[@"NAS",phoneTitle,myTitle];
  334. NSArray *imageNArr = @[@"tabbar_nas_N", @"tabbar_phone_N",@"tabbar_my_N"];
  335. NSArray *imageHArr = @[@"tabbar_nas_H", @"tabbar_phone_H",@"tabbar_my_H"];
  336. for (int i=0; i<viewControllers.count; i++) {
  337. UITabBarItem * tabBarItem = [UITabBarItem new];
  338. tabBarItem.title = titleArr[i];
  339. tabBarItem.selectedImage = [[UIImage imageNamed:imageHArr[i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  340. tabBarItem.image = [[UIImage imageNamed:imageNArr[i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  341. UIViewController *curVC = viewControllers[i];
  342. curVC.tabBarItem = tabBarItem;
  343. }
  344. // tabBarController.tabBar.barTintColor = [UIColor hwColor:@"#F6F8FA"]; // 设置标签栏背景色
  345. // tabBarController.tabBar.tintColor = [UIColor hwColor:@"#01B7EA"]; // 设置选中标签项的颜色
  346. tabBarController.tabBar.backgroundColor = [UIColor whiteColor];
  347. [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor hwColor:@"#F6F8FA"],NSForegroundColorAttributeName, [UIFont systemFontOfSize:12.0],NSFontAttributeName,nil] forState:UIControlStateNormal];
  348. [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor hwColor:@"#01B7EA"],NSForegroundColorAttributeName, [UIFont systemFontOfSize:12.0],NSFontAttributeName,nil] forState:UIControlStateSelected];
  349. ksharedAppDelegate.mainTabBar = tabBarController;
  350. self.window.rootViewController = tabBarController;
  351. [self.window makeKeyAndVisible];
  352. }
  353. #pragma mark 处理进来是非隐私模式的情况
  354. - (void)HandleEnterNotPrivacyModeFun
  355. {
  356. #ifdef developJSQ
  357. NSInteger maskModel = 1;// [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  358. #else
  359. NSInteger maskModel = [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  360. #endif
  361. if (maskModel != 0){
  362. [HWDataManager setIntegerWithKey:Const_Mask_View_Model value:0];
  363. [iTools lc_setAlternateIconName:@"AppIcon1"];
  364. }
  365. }
  366. - (void)setPwdOk{
  367. [self enterMainVCFromScene];
  368. // NSArray *dataArray = [BaseModel bg_findAll:DB_BrowserWindows_TableName];
  369. //
  370. // if (dataArray.count == 0) { // 浏览器没有窗口
  371. // // 加载首页
  372. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  373. // vc.webUrl = Const_HomeUrl;
  374. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  375. // self.window.rootViewController = nvc;
  376. //
  377. // }else {
  378. // // 浏览器当前窗口索引ID
  379. // NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  380. // NSString *where = [NSString stringWithFormat:@"where %@=%ld",bg_sqlKey(@"ID"),(long)ID];
  381. // NSArray* finfAlls = [BaseModel bg_find:DB_BrowserWindows_TableName where:where];
  382. // BaseModel *model = finfAlls.firstObject;
  383. //
  384. // // 加载网页
  385. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  386. // vc.webUrl = model.webUrl;
  387. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  388. // self.window.rootViewController = nvc;
  389. // }
  390. }
  391. /** 登录界面 - 外部使用*/
  392. + (void)enterLoginVC {
  393. // SetPWDViewController *vc = [[SetPWDViewController alloc] init];
  394. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  395. // UIWindow *keyWindow = [iTools getKeyWindow];
  396. // keyWindow.rootViewController = nvc;
  397. }
  398. /** 主界面 - 外部使用 */
  399. + (void)enterMainVC {
  400. // AlbumHomeViewController *vc = [[AlbumHomeViewController alloc] init];
  401. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  402. // UIWindow *keyWindow = [iTools getKeyWindow];
  403. // keyWindow.rootViewController = nvc;
  404. }
  405. - (void)sceneDidDisconnect:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  406. HLog(@"sceneDidDisconnect");
  407. //[[boxDownloadFileManager shareInstance] suspendDownloadFileFun:YES withModel:nil withItem:nil];
  408. }
  409. - (void)sceneDidBecomeActive:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  410. // BOOL haveGuide = [HWDataManager getBoolWithKey:Const_Have_Show_Guide];
  411. // if (haveGuide) {
  412. // ;
  413. // }else {
  414. //
  415. // return;
  416. // }
  417. // [self showCalculatorVC];
  418. }
  419. - (void)sceneWillResignActive:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  420. BOOL haveGuide = [HWDataManager getBoolWithKey:Const_Have_Show_Guide];
  421. if (haveGuide) {
  422. ;
  423. }else {
  424. return;
  425. }
  426. [self showCalculatorVC];
  427. }
  428. - (void)sceneWillEnterForeground:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  429. }
  430. - (void)sceneDidEnterBackground:(UIScene *)scene API_AVAILABLE(ios(13.0)){
  431. BOOL haveGuide = [HWDataManager getBoolWithKey:Const_Have_Show_Guide];
  432. if (haveGuide) {
  433. ;
  434. }else {
  435. return;
  436. }
  437. [self showCalculatorVC];
  438. }
  439. - (void)scene:(UIScene *)scene continueUserActivity:(NSUserActivity *)userActivity {
  440. if([TencentOAuth CanHandleUniversalLink:userActivity.webpageURL]){
  441. [TencentOAuth HandleUniversalLink:userActivity.webpageURL];
  442. }
  443. else{
  444. [WXApi handleOpenUniversalLink:userActivity delegate:self];
  445. }
  446. }
  447. - (void)scene:(UIScene *)scene openURLContexts:(NSSet<UIOpenURLContext *> *)URLContexts {
  448. NSEnumerator *enumerator = [URLContexts objectEnumerator];
  449. UIOpenURLContext *context;
  450. while (context = [enumerator nextObject]) {
  451. NSLog(@"context.URL =====%@",context.URL);
  452. //openprivacyxapp://page?param1=value1&param2=value2
  453. NSString *curStr = context.URL.absoluteString;
  454. if([curStr rangeOfString:@"openprivacyxapp://page"].location != NSNotFound){
  455. _getShareStr = curStr;
  456. [self delayedHandlShareAwakenAppBy:curStr];
  457. break;
  458. }
  459. else{
  460. [WXApi handleOpenURL:context.URL delegate:self];
  461. }
  462. //NSLog(@"context.options.sourceApplication ===== %@",context.options.sourceApplication);
  463. }
  464. _session = nil;
  465. _connectionOptions = nil;
  466. }
  467. - (void)delayedHandlShareAwakenAppBy:(NSString*)curStr{
  468. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  469. [self shareAwakenAppBy:curStr];
  470. });
  471. }
  472. #pragma mark 初始化数据库-DB_BrowserWindows_TableName
  473. - (void)initBrowserWindow {
  474. // 浏览器当前所有窗口
  475. NSArray *dataArray = [BaseModel bg_findAll:DB_BrowserWindows_TableName];
  476. // 浏览器当前窗口索引ID
  477. NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  478. NSString *IDValue = [NSString stringWithFormat:@"%ld", ID];
  479. NSString *where = [NSString stringWithFormat:@"where %@=%@",bg_sqlKey(@"ID"),bg_sqlValue(IDValue)];
  480. NSArray *modelArr = [BaseModel bg_find:DB_BrowserWindows_TableName where:where];
  481. if (dataArray.count == 0) { // 浏览器没有窗口
  482. BaseModel *model = [[BaseModel alloc] init];
  483. model.ID = 0;
  484. model.name = @"主页";
  485. // model.iconFile = imageUrl;
  486. model.webUrl = Const_HomeUrl;
  487. // 写入数据库
  488. model.bg_tableName = DB_BrowserWindows_TableName;
  489. [model bg_saveOrUpdateAsync:^(BOOL isSuccess) {
  490. HLog(@"BaseModel写入:%@", isSuccess ? @"成功":@"失败");
  491. }];
  492. // 浏览器当前窗口索引ID
  493. [HWDataManager setIntegerWithKey:BrowserWindowsCurrentID value:0];
  494. }else if (modelArr.count == 0) { // 新建窗口
  495. BaseModel *model = [[BaseModel alloc] init];
  496. model.ID = ID;
  497. model.name = @"主页";
  498. // model.iconFile = imageUrl;
  499. model.webUrl = Const_HomeUrl;
  500. // 写入数据库
  501. model.bg_tableName = DB_BrowserWindows_TableName;
  502. [model bg_saveOrUpdateAsync:^(BOOL isSuccess) {
  503. HLog(@"BaseModel写入:%@", isSuccess ? @"成功":@"失败");
  504. }];
  505. }else { // 更新窗口数据
  506. // 浏览器当前窗口索引ID
  507. // NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  508. //
  509. // BaseModel *model = [[BaseModel alloc] init];
  510. // model.ID = ID;
  511. // model.name = @"主页";
  512. //// model.iconFile = imageUrl;
  513. // model.webUrl = Const_HomeUrl;
  514. //
  515. // // 更新数据库
  516. // model.bg_tableName = DB_BrowserWindows_TableName;
  517. // [model bg_saveOrUpdateAsync:^(BOOL isSuccess) {
  518. // HLog(@"BaseModel更新: %@", isSuccess ? @"成功":@"失败");
  519. // }];
  520. }
  521. }
  522. #pragma mark 获取当前屏幕的截图
  523. //- (UIImage *)getScreenShotImage {
  524. // CGSize size = [UIScreen mainScreen].bounds.size;
  525. // CGFloat scale = [UIScreen mainScreen].scale;
  526. // UIGraphicsBeginImageContextWithOptions(size, YES, scale);
  527. // [self.window.layer renderInContext:UIGraphicsGetCurrentContext()];
  528. // UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
  529. // UIGraphicsEndImageContext();
  530. // return image;
  531. //}
  532. #pragma mark 计算器伪装视图
  533. /*CalculatorViewController*/
  534. - (void)showCalculatorVC{
  535. if(ksharedAppDelegate.getSystemPermissType){
  536. HLog(@"检测到获取系统全进入后台");
  537. return;
  538. }
  539. //修复扫描已经有密码的合作 点击跳过因为网络弹框再次覆盖一次密码(需要输入两次密码)
  540. BaseNavigationController*curTopNav = (BaseNavigationController*)[iTools appRootViewController];
  541. if([curTopNav isKindOfClass:[BaseNavigationController class]]){
  542. NSArray *vcArr = [curTopNav viewControllers];
  543. if(vcArr && vcArr.count >0){
  544. UIViewController *lastVC = vcArr.lastObject;
  545. if([lastVC isKindOfClass:[inputPWDViewController class]]){
  546. return;
  547. }
  548. }
  549. }
  550. /*无有效时长直接返回不加载任何加密界面*/
  551. NSString *PwdStr = nil;
  552. NSDictionary *deviceDict = [HWDataManager getObjectWithKey:Const_Have_Add_Device];
  553. //本地密码本地判断 密码改在服务器保持
  554. if ([[deviceDict allKeys] containsObject:Const_Have_Add_Device_PWD]){
  555. PwdStr = [deviceDict objectForKey:Const_Have_Add_Device_PWD];
  556. }
  557. //实时拿到的密码 (每次打开或者更换设备 通过SN重新拿)
  558. if([connectDeviceManager shareInstance].DeviceThirdIdMod.data.password){
  559. NSString *curPwd = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.password;
  560. NSString*desPwdStr = [RSATool AES128Decrypt:curPwd key:AESCODEKEEYY];
  561. if(desPwdStr){
  562. PwdStr = desPwdStr;
  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(![connectDeviceManager shareInstance].DeviceThirdIdMod){
  582. return;
  583. }
  584. BOOL isPrivacyMode = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.isPrivacyMode;
  585. if(!isPrivacyMode)
  586. {
  587. [connectDeviceManager shareInstance].isFirstInputPwdDone = YES;
  588. [[NSNotificationCenter defaultCenter] postNotificationName:ShowImgAndVoiceNotification object:nil];
  589. return;
  590. }
  591. #ifdef developJSQ
  592. NSInteger maskModel = 1;// [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  593. #else
  594. NSInteger maskModel = [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
  595. #endif
  596. if (maskModel == 0){
  597. //输入密码界面
  598. [self closeCalculatorVC];
  599. _inputVC = [[inputPWDViewController alloc] init];
  600. [self.window addSubview:_inputVC.view];
  601. _isDidShowPwdType = YES;
  602. }
  603. else if (maskModel == 2){
  604. /*浏览器*/
  605. [self closeCalculatorVC];
  606. _webVC = [[HWWebViewController alloc] init];
  607. _webVC.pwd = PwdStr;
  608. _webVC.webUrl = @"https://baidu.com";
  609. [self.window addSubview:_webVC.view];
  610. _isDidShowPwdType = YES;
  611. }else{
  612. /*计算器*/
  613. [self closeCalculatorVC];
  614. _calculatorVC = [[CalculatorViewController alloc] init];
  615. _calculatorVC.pwd = PwdStr;
  616. [self.window addSubview:_calculatorVC.view];
  617. _isDidShowPwdType = YES;
  618. }
  619. [[NSNotificationCenter defaultCenter] postNotificationName:ShowPwdVCNotification object:nil];
  620. }
  621. - (void)closeCalculatorVC{
  622. ksharedAppDelegate.getSystemPermissType = NO;
  623. if (_calculatorVC){
  624. [_calculatorVC.view removeFromSuperview];
  625. }
  626. /*浏览器*/
  627. if (_webVC){
  628. [_webVC.view removeFromSuperview];
  629. }
  630. if(_inputVC){
  631. [_inputVC.view removeFromSuperview];
  632. }
  633. _isDidShowPwdType = NO;
  634. if(self->_session && self->_connectionOptions){
  635. [self scene:self->_session openURLContexts:self->_connectionOptions.URLContexts];
  636. }
  637. }
  638. - (NSString *)documentPathForAccount:(NSString *)account fileFolder:(NSString *)fileFolder {
  639. NSString *path = DocumentPath;
  640. if (account.length != 0) {
  641. path = [NSString stringWithFormat:@"%@/%@/",DocumentPath,account];
  642. }
  643. if ([fileFolder containsString:@"/"]) {
  644. NSString *path1 = [path stringByAppendingPathComponent:fileFolder];
  645. path1 = [path1 stringByDeletingLastPathComponent];
  646. NSError *error;
  647. if (![[NSFileManager defaultManager] fileExistsAtPath:path1]) {
  648. [[NSFileManager defaultManager] createDirectoryAtPath:path1 withIntermediateDirectories:YES attributes:nil error:&error];
  649. }
  650. }else{
  651. NSError *error;
  652. if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
  653. [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error];
  654. }
  655. }
  656. return [path stringByAppendingPathComponent:fileFolder];
  657. }
  658. - (void)startUseBtnBePressed{
  659. [self enterMainVCFromScene];
  660. // NSString *launchAppPWDPath = [self documentPathForAccount:@"" fileFolder:@"LaunchPWD"];
  661. // NSString *str = [[NSString alloc] initWithContentsOfFile:launchAppPWDPath encoding:(NSUTF8StringEncoding) error:nil];
  662. // if (!str || [str isEqualToString:@"0"])
  663. // {
  664. // SetUsePWDViewController *loginVC = [[SetUsePWDViewController alloc] init];
  665. // loginVC.delegate = self;
  666. // self.window.rootViewController = loginVC;
  667. //
  668. // return;
  669. // }
  670. //
  671. // NSArray *dataArray = [BaseModel bg_findAll:DB_BrowserWindows_TableName];
  672. //
  673. // if (dataArray.count == 0) { // 浏览器没有窗口
  674. // // 加载首页
  675. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  676. // vc.webUrl = Const_HomeUrl;
  677. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  678. // self.window.rootViewController = nvc;
  679. //
  680. // }else {
  681. // // 浏览器当前窗口索引ID
  682. // NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  683. // NSString *where = [NSString stringWithFormat:@"where %@=%ld",bg_sqlKey(@"ID"),(long)ID];
  684. // NSArray* finfAlls = [BaseModel bg_find:DB_BrowserWindows_TableName where:where];
  685. // BaseModel *model = finfAlls.firstObject;
  686. //
  687. // // 加载网页
  688. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  689. // vc.webUrl = model.webUrl;
  690. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  691. // self.window.rootViewController = nvc;
  692. // }
  693. }
  694. - (void)loginOk{
  695. [self enterMainVCFromScene];
  696. }
  697. - (void)guideOk:(NSNotification*)not{
  698. NSString *object = not.object;
  699. if(object && [object isEqualToString:@"isLoginAgainType"]){
  700. self.isLoginAgainType = YES;
  701. }
  702. [self enterMainVCFromScene];
  703. //clear下载和上传的已经获取的数据
  704. [[uploadFileManager shareInstance] suspendUploadFileFun:YES withModel:nil];
  705. [uploadFileManager shareInstance].databaseArr = [NSMutableArray new];
  706. [uploadFileManager shareInstance].fileModelDataArr = [NSMutableArray new];
  707. [uploadFileManager shareInstance].curUploadFileDataModel.curUploadStateType = uploadStateWait;
  708. [[downloadManager shareInstance] suspendDownloadFileFun:YES withModel:nil];
  709. [downloadManager shareInstance].databaseArr = [NSMutableArray new];
  710. [downloadManager shareInstance].downLoadFileModelDataArr = [NSMutableArray new];
  711. [[backupsFileManager shareInstance] suspendBackupsFileFun];
  712. //frp的下载
  713. [[customDownloadManager shareManager] suspendAllDownloadTask];
  714. NSString *uid =[connectDeviceManager shareInstance].DeviceThirdIdMod.data.sn;
  715. if(uid){
  716. }
  717. else{
  718. uid = @"";
  719. }
  720. [customDownloadManager shareManager].uid = uid;
  721. [lastFileManager shareManager].uid = uid;
  722. }
  723. #pragma mark 上报版本号信息
  724. -(void)reportVersionInfoFun
  725. {
  726. NSMutableDictionary *paraDict = [NSMutableDictionary new];
  727. NSString *vers = [iPhone appVersion];
  728. if(vers){
  729. [paraDict setValue:vers forKey:@"iosClientVersionNumber"];
  730. }
  731. NSDictionary *deviceDict = [HWDataManager getObjectWithKey:Const_Have_Add_Device];
  732. if (deviceDict && [[deviceDict allKeys] containsObject:Const_Have_Add_Device_SN]){
  733. NSString*snStr = deviceDict[Const_Have_Add_Device_SN];
  734. if(snStr){
  735. [paraDict setValue:snStr forKey:@"sn"];
  736. }
  737. else{
  738. return;
  739. }
  740. }
  741. else{
  742. return;;
  743. }
  744. // KWeakSelf
  745. [[netWorkManager shareInstance] CommonPostCallBackCode:reportVersionInfo Parameters:paraDict success:^(id _Nonnull responseObject) {
  746. } failure:^(NSError * _Nonnull error) {
  747. }];
  748. }
  749. #pragma mark 获取NAS相关信息
  750. -(void)getNASMsgFun
  751. {
  752. NSMutableDictionary *paraDict = [NSMutableDictionary new];
  753. NSString *SNStr = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.changeSn;
  754. if(SNStr){
  755. [paraDict setValue:SNStr forKey:@"sn"];
  756. }
  757. else{
  758. return;;
  759. }
  760. KWeakSelf
  761. [[netWorkManager shareInstance] CommonGetWithCallBackCode:getIpFun Parameters:paraDict success:^(id _Nonnull responseObject){
  762. NASMsgModel *model = [[NASMsgModel alloc] initWithDictionary:responseObject error:nil];
  763. if(model){
  764. ksharedAppDelegate.NASMsgMod = model;
  765. }
  766. } failure:^(NSError * _Nonnull error) {
  767. }];
  768. }
  769. #pragma mark 主动上锁
  770. - (void)showLockViewFun:(NSNotification*)not
  771. {
  772. [self showCalculatorVC];
  773. }
  774. #pragma mark 进入设置密码
  775. //- (void)setPwdVCFun:(NSNotification*)not
  776. //{
  777. // _isNeedToShowSecretKey = YES;
  778. //}
  779. #pragma mark 忘记密码
  780. - (void)forgetPwdFun:(NSNotification*)not
  781. {
  782. /*忘记密码*/
  783. forgetPwdViewController *forgetPwdVC = [[forgetPwdViewController alloc] init];
  784. BaseNavigationController *forgetPwdVCNav = [[BaseNavigationController alloc] initWithRootViewController:forgetPwdVC];
  785. self.window.rootViewController = forgetPwdVCNav;
  786. }
  787. #pragma mark 忘记密码返回
  788. - (void)forgetPwdBackFun:(NSNotification*)not
  789. {
  790. // if(_preRootPlayerNav)
  791. // {
  792. // self.window.rootViewController = _preRootPlayerNav;
  793. // }
  794. // else{
  795. [self enterMainVCFromScene];
  796. //}
  797. [self showCalculatorVC];
  798. }
  799. #pragma mark 忘记密码设置密码完成
  800. - (void)forgetPwdDidSetPwdFun:(NSNotification*)not
  801. {
  802. // if(_preRootPlayerNav)
  803. // {
  804. // NSArray *vcArr = _preRootPlayerNav.viewControllers;
  805. // if(vcArr.count > 2){
  806. // [_preRootPlayerNav popToViewController:vcArr[1] animated:NO];
  807. // }
  808. // self.window.rootViewController = _preRootPlayerNav;
  809. // }
  810. // else{
  811. [self enterMainVCFromScene];
  812. //}
  813. [self closeCalculatorVC];
  814. _curPlayerVC.isPwdVCShow = NO;
  815. [_curPlayerVC setShowImgAndVoiceTypeFun:YES];
  816. [connectDeviceManager shareInstance].isFirstInputPwdDone = YES;
  817. }
  818. #pragma mark 扫码切换设备 scanChangeDeviceNotification
  819. - (void)scanChangeDeviceFun:(NSNotification*)not
  820. {
  821. TipsQRCodeForChangeDeviceViewController *nextVC = [[TipsQRCodeForChangeDeviceViewController 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 && _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. //HLog(@"hxd %ld",index);
  1074. int eventType = 1;
  1075. NSString* eventValue = @"Nas";
  1076. if(index == 0){
  1077. eventValue = @"Nas";
  1078. }
  1079. else if(index == 1){
  1080. eventValue = @"Cloud";
  1081. }
  1082. else if(index == 1){
  1083. eventValue = @"Home";
  1084. }
  1085. //数据埋点
  1086. [[netWorkManager shareInstance] DataEmbeddingPointBy:eventType withEventValue:eventValue];
  1087. }
  1088. @end