SceneDelegate.m 45 KB

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