SceneDelegate.m 47 KB

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