cloudPhoneViewController.m 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. //
  2. // cloudPhoneViewController.m
  3. // 双子星云手机
  4. //
  5. // Created by xd h on 2024/6/20.
  6. //
  7. #import "cloudPhoneViewController.h"
  8. #import "cloudPhoneSetView.h"
  9. #import "PlayerViewController.h"
  10. #import "audioPlayingView.h"
  11. #import "DFPlayer.h"
  12. #import "audioPlayerViewController.h"
  13. #import "webRtcMsgModel.h"
  14. #import "webRtcPlayerViewController.h"
  15. @interface cloudPhoneViewController ()
  16. @property (nonatomic,strong) cloudPhoneSetView *cloudPhoneSetV;
  17. @property (nonatomic,strong) webRtcMsgModel *webRtcMsgMod;
  18. @end
  19. @implementation cloudPhoneViewController
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. // Do any additional setup after loading the view.
  23. //输入密码完成
  24. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didInpuPwdOkFun) name:didInputPWDNotification object:nil];
  25. [self.view setBackgroundColor:HWF5F7FAColor];
  26. [self.toolBar setHidden:YES];
  27. [self.navigationBar setHidden:YES];
  28. [self.navBarBGView setHidden:YES];
  29. [self drawAnyView];
  30. }
  31. - (void)drawAnyView{
  32. //顶底底部图片
  33. UIImageView *topImageV = [UIImageView new];
  34. topImageV.userInteractionEnabled = YES;
  35. topImageV.image = [UIImage imageNamed:@"cloudPhone_bg"];
  36. [self.view addSubview:topImageV];
  37. [topImageV mas_makeConstraints:^(MASConstraintMaker *make) {
  38. make.top.mas_equalTo(0);
  39. make.left.mas_equalTo(0);
  40. make.right.mas_equalTo(0);
  41. make.bottom.mas_equalTo(0);
  42. }];
  43. CGFloat width = SCREEN_W;
  44. CGFloat height = SCREEN_H;
  45. BOOL isSmallPhoneType = NO;
  46. if(width == 375 && height == 667){
  47. isSmallPhoneType = YES;
  48. }
  49. CGFloat adjustSmallScale = 1.0;
  50. if(isSmallPhoneType){
  51. adjustSmallScale = 0.9;
  52. }
  53. CGFloat imageTopY = 54.0;
  54. if(isSmallPhoneType){
  55. imageTopY = 20.0;
  56. }
  57. //设置按钮
  58. UIButton *setButton = [[UIButton alloc] init];
  59. //[setButton setBackgroundImage:[UIImage imageNamed:@"cloudPhone_set"] forState:UIControlStateNormal];
  60. [setButton setImage:[UIImage imageNamed:@"cloudPhone_set"] forState:UIControlStateNormal];
  61. setButton.tag = 1;
  62. [setButton addTarget:self action:@selector(didClickButtonFun:) forControlEvents:UIControlEventTouchUpInside];
  63. [self.view addSubview:setButton];
  64. //setButton.backgroundColor = [UIColor greenColor];
  65. [setButton mas_makeConstraints:^(MASConstraintMaker *make) {
  66. make.top.mas_equalTo(imageTopY);
  67. if(isSmallPhoneType){
  68. make.right.mas_equalTo(-5);
  69. }
  70. else{
  71. make.right.mas_equalTo(-16);
  72. }
  73. make.width.mas_equalTo(50);
  74. make.height.mas_equalTo(50);
  75. // make.top.mas_equalTo(imageTopY);
  76. // make.right.mas_equalTo(-16);
  77. // make.width.mas_equalTo(24);
  78. // make.height.mas_equalTo(24);
  79. }];
  80. //中间图片
  81. UIImageView *midImageV = [UIImageView new];
  82. midImageV.userInteractionEnabled = YES;
  83. midImageV.image = [UIImage imageNamed:@"cloudPhone_mid_img"];
  84. [self.view addSubview:midImageV];
  85. [midImageV mas_makeConstraints:^(MASConstraintMaker *make) {
  86. make.width.mas_equalTo(326*WAUTOSCALE*adjustSmallScale);
  87. make.height.mas_equalTo(608*WAUTOSCALE*adjustSmallScale);
  88. make.centerX.mas_equalTo(0);
  89. make.centerY.mas_equalTo(-10);
  90. }];
  91. NSString *midTopTipImageStr = @"cloudPhone_topTip_img_cs";
  92. //欢迎
  93. //en-US 英文 ja-JP 日文
  94. NSArray *arLanguages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];
  95. NSLog(@"arLanguages:%@",arLanguages);
  96. ///获取设备当前地区的代码和APP语言环境
  97. NSString *languageCode = [NSLocale preferredLanguages][0];
  98. //目前支持 中文(简体 繁体) 英文 日语
  99. if([languageCode rangeOfString:@"zh-Hans"].location != NSNotFound)
  100. {
  101. midTopTipImageStr = @"cloudPhone_topTip_img_cs";
  102. }
  103. else if([languageCode rangeOfString:@"zh-Hant"].location != NSNotFound)
  104. {
  105. midTopTipImageStr = @"cloudPhone_topTip_img_ct";
  106. }
  107. else{
  108. midTopTipImageStr = @"cloudPhone_topTip_img_en";
  109. }
  110. //提示文字图片
  111. UIImageView *midTopTipImageV = [UIImageView new];
  112. midTopTipImageV.image = [UIImage imageNamed:midTopTipImageStr];
  113. [midImageV addSubview:midTopTipImageV];
  114. [midTopTipImageV mas_makeConstraints:^(MASConstraintMaker *make) {
  115. make.width.mas_equalTo(282*WAUTOSCALE*adjustSmallScale);
  116. make.height.mas_equalTo(84*WAUTOSCALE*adjustSmallScale);
  117. make.centerX.mas_equalTo(0);
  118. make.top.equalTo(midImageV.mas_top).offset(64);
  119. }];
  120. //进入云机
  121. UIButton*enterCloudPhoneButton = [[UIButton alloc] init];
  122. CGFloat w_btn = SCREEN_W - 15*2 - 50*2;
  123. // gradient
  124. CAGradientLayer *gl = [CAGradientLayer layer];
  125. gl.frame = CGRectMake(0,0,w_btn,44.f);
  126. gl.startPoint = CGPointMake(0, 0.5);
  127. gl.endPoint = CGPointMake(0.97, 0.5);
  128. gl.colors = @[(__bridge id)HW0CDEFDColor.CGColor, (__bridge id)HW058DFBColor.CGColor];
  129. gl.locations = @[@(0), @(1.0f)];
  130. [enterCloudPhoneButton.layer addSublayer:gl];
  131. [enterCloudPhoneButton setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
  132. //[enterCloudPhoneButton addTarget:self action:@selector(didClickButtonFun:) forControlEvents:(UIControlEventTouchUpInside)];
  133. [enterCloudPhoneButton setTitle:NSLocalizedString(@"cloudPhone_enter_tip",nil) forState:(UIControlStateNormal)];
  134. [enterCloudPhoneButton.titleLabel setFont:[UIFont systemFontOfSize:16.f]];
  135. [enterCloudPhoneButton.layer setCornerRadius:21.f];
  136. enterCloudPhoneButton.layer.borderWidth = 1.5;
  137. enterCloudPhoneButton.layer.borderColor = [UIColor whiteColor].CGColor;
  138. enterCloudPhoneButton.clipsToBounds = YES;
  139. //enterCloudPhoneButton.tag = 2;
  140. [midImageV addSubview:enterCloudPhoneButton];
  141. [enterCloudPhoneButton mas_makeConstraints:^(MASConstraintMaker *make) {
  142. make.width.mas_equalTo(w_btn);
  143. make.height.mas_equalTo(42);
  144. make.centerX.mas_equalTo(0);
  145. make.bottom.equalTo(midImageV.mas_bottom).offset(-60);
  146. }];
  147. //扩大金融云机范围按钮
  148. UIButton *bigButton = [[UIButton alloc] init];
  149. bigButton.tag = 2;
  150. [bigButton addTarget:self action:@selector(didClickButtonFun:) forControlEvents:UIControlEventTouchUpInside];
  151. [self.view addSubview:bigButton];
  152. //bigButton.backgroundColor = [UIColor greenColor];
  153. [bigButton mas_makeConstraints:^(MASConstraintMaker *make) {
  154. make.top.equalTo(midImageV.mas_top).offset(0);
  155. make.right.equalTo(midImageV.mas_right).offset(0);
  156. make.left.equalTo(midImageV.mas_left).offset(0);
  157. make.bottom.equalTo(midImageV.mas_bottom).offset(0);
  158. }];
  159. }
  160. #pragma mark 点击按钮
  161. - (void)didClickButtonFun:(UIButton*)but
  162. {
  163. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable)
  164. {
  165. [[iToast makeText:NSLocalizedString(@"phone_network_fail_Tips",nil)] show];
  166. return;
  167. }
  168. // if (!ksharedAppDelegate.isWebSockLinkOKAginType) {//未链接
  169. // [[iToast makeText:NSLocalizedString(@"box_link_error_show_tip",nil)] show];
  170. // return;
  171. // }
  172. NSInteger tag = but.tag;
  173. HLog(@"%ld",tag);
  174. switch (tag) {
  175. case 1:
  176. {
  177. //数据埋点
  178. [[netWorkManager shareInstance] DataEmbeddingPointBy:2 withEventValue:@"Cloud_settings"];
  179. _cloudPhoneSetV = [cloudPhoneSetView new];
  180. [ksharedAppDelegate.window addSubview:_cloudPhoneSetV];
  181. [_cloudPhoneSetV mas_makeConstraints:^(MASConstraintMaker *make) {
  182. make.left.mas_equalTo(0);
  183. make.right.mas_equalTo(0);
  184. make.top.mas_equalTo(0);
  185. make.bottom.mas_equalTo(0);
  186. }];
  187. KWeakSelf
  188. _cloudPhoneSetV.didClickButtonFun = ^(NSInteger tag) {
  189. if (tag == 10) {//重启
  190. [weakSelf didClickRestartFun];
  191. }
  192. else if (tag == 11){//恢复出厂
  193. [weakSelf RestoreFactoryAleartFun];
  194. }
  195. };
  196. }
  197. break;
  198. case 2:
  199. {
  200. //[self checkFullScreenWithTVShowStateFun];
  201. // PlayerViewController *vc = [PlayerViewController new];
  202. // [self pushViewController:vc animated:YES];
  203. //
  204. // if(ksharedAppDelegate.TvStatusMod.isTVShowType){
  205. // [[iToast makeText:NSLocalizedString(@"tv_p2p_ing",nil)] show];
  206. // }
  207. [self queryWebRtcMsgFun:YES];
  208. //数据埋点
  209. [[netWorkManager shareInstance] DataEmbeddingPointBy:2 withEventValue:@"Cloud_enter"];
  210. }
  211. break;
  212. default:
  213. break;
  214. }
  215. }
  216. #pragma mark 点击了重启空间
  217. - (void)didClickRestartFun
  218. {
  219. KWeakSelf
  220. /*弹窗提示重启*/
  221. ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"my_set_no_restart_phone_tips",nil)
  222. msg:@""
  223. imageStr:@""
  224. cancelTitle:NSLocalizedString(@"other_cancel",nil)
  225. okTitle:NSLocalizedString(@"my_set_no_restart_phone_btn_ok",nil) isOkBtnHighlight:NO
  226. didClickOk:^{
  227. [weakSelf sureToRestartCloudPhoneFun];
  228. } didClickCancel:^{
  229. }];
  230. nextVC.modalPresentationStyle = UIModalPresentationCustom;
  231. [self presentViewController:nextVC animated:YES completion:^{
  232. nextVC.view.superview.backgroundColor = [UIColor clearColor];
  233. }];
  234. }
  235. #pragma mark 确认重启云机
  236. - (void)sureToRestartCloudPhoneFun{
  237. // /*重启云手机*/
  238. // 通过指令通道发送 {"type":"reboot"}
  239. [[webRtcManager shareManager] needToRebootFun];
  240. //提示语
  241. [[iToast makeText:NSLocalizedString(@"player_link_rebooting_Tips",nil)] show];
  242. }
  243. #pragma mark 点击恢复出厂
  244. - (void)RestoreFactoryAleartFun
  245. {
  246. KWeakSelf
  247. /*弹窗提示恢复出厂*/
  248. ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"my_set_no_Restore_Factory_tips",nil)
  249. msg:NSLocalizedString(@"my_set_no_Restore_Factory_msg",nil)
  250. imageStr:@"icon_Restore_Factory_big"
  251. cancelTitle:NSLocalizedString(@"my_set_TVP2P_Open_sure",nil)
  252. okTitle:NSLocalizedString(@"other_cancel",nil) isOkBtnHighlight:YES
  253. didClickOk:^{
  254. } didClickCancel:^{
  255. //点击确定
  256. [weakSelf gotoResetFun];
  257. }];
  258. nextVC.modalPresentationStyle = UIModalPresentationCustom;
  259. [self presentViewController:nextVC animated:YES completion:^{
  260. nextVC.view.superview.backgroundColor = [UIColor clearColor];
  261. }];
  262. }
  263. #pragma mark 点击了恢复出厂
  264. - (void)gotoResetFun
  265. {
  266. [[webRtcManager shareManager] needToResetFun];
  267. [self RestoreFactoryingFun];
  268. }
  269. #pragma mark 恢复出厂中
  270. - (void)RestoreFactoryingFun
  271. {
  272. KWeakSelf
  273. /*弹窗提示恢复出厂*/
  274. ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"my_set_no_Restore_Factorying_tips",nil)
  275. msg:NSLocalizedString(@"my_set_no_Restore_Factorying_msg",nil)
  276. imageStr:@""
  277. cancelTitle:NSLocalizedString(@"my_set_no_Restore_Factorying",nil)
  278. okTitle:@""
  279. isOkBtnHighlight:NO
  280. didClickOk:^{
  281. [weakSelf RestoreFactoryCompleteFun];
  282. } didClickCancel:^{
  283. }];
  284. [nextVC setButtonCountdownFun:180];//90
  285. nextVC.modalPresentationStyle = UIModalPresentationCustom;
  286. [self presentViewController:nextVC animated:YES completion:^{
  287. nextVC.view.superview.backgroundColor = [UIColor clearColor];
  288. }];
  289. }
  290. #pragma mark 恢复出厂倒计时结束
  291. - (void)RestoreFactoryCompleteFun
  292. {
  293. //KWeakSelf
  294. //瑞云发起重连
  295. //[[connectDeviceManager shareInstance] onConnectFun];
  296. /*弹窗提示恢复出厂*/
  297. ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"my_set_no_Restore_Factory_ok_tips",nil)
  298. msg:@""
  299. imageStr:@""
  300. cancelTitle:NSLocalizedString(@"my_set_no_Restore_FactoryOK",nil)
  301. okTitle:@""
  302. isOkBtnHighlight:NO
  303. didClickOk:^{
  304. } didClickCancel:^{
  305. }];
  306. nextVC.modalPresentationStyle = UIModalPresentationCustom;
  307. [self presentViewController:nextVC animated:YES completion:^{
  308. nextVC.view.superview.backgroundColor = [UIColor clearColor];
  309. }];
  310. }
  311. - (void)viewWillAppear:(BOOL)animated{
  312. [super viewWillAppear:animated];
  313. [self handelAudioPlayingViewFun];
  314. }
  315. - (void)viewWillDisappear:(BOOL)animated{
  316. [super viewWillDisappear:animated];
  317. }
  318. - (void)pushViewController:(UIViewController*)vc animated:(BOOL)animated
  319. {
  320. [self.navigationController pushViewController:vc animated:animated];
  321. }
  322. #pragma mark 处理音频播放中的视图状态
  323. - (void)handelAudioPlayingViewFun
  324. {
  325. audioPlayingView * audioPlayingV = [audioPlayingView sharedInstance];
  326. if([DFPlayer sharedPlayer].state == DFPlayerStateBuffering
  327. ||[DFPlayer sharedPlayer].state == DFPlayerStatePlaying
  328. ||[DFPlayer sharedPlayer].state == DFPlayerStatePause){//播放中
  329. [self showAudioPlayingViewFun];
  330. }
  331. else{
  332. [self hideAudioPlayingViewFun];
  333. }
  334. KWeakSelf
  335. audioPlayingV.didClickButtonFun = ^(NSInteger tag) {
  336. if(tag == 1){
  337. [weakSelf hideAudioPlayingViewFun];
  338. }
  339. else if(tag == 5){
  340. [weakSelf AudioPlayingGotoAudioPlayerVCFun];
  341. }
  342. };
  343. }
  344. - (void)AudioPlayingGotoAudioPlayerVCFun{
  345. audioPlayerViewController *vc = [audioPlayerViewController new];
  346. vc.isfirstEnterType = NO;
  347. [self.navigationController pushViewController:vc animated:YES];
  348. }
  349. #pragma mark 显示音频播放中的视图
  350. - (void)showAudioPlayingViewFun
  351. {
  352. audioPlayingView * audioPlayingV = [audioPlayingView sharedInstance];
  353. [self.view addSubview:audioPlayingV];
  354. if([DFPlayer sharedPlayer].state == DFPlayerStatePlaying){
  355. [audioPlayingV startRotatingImage];
  356. }
  357. else if ([DFPlayer sharedPlayer].state == DFPlayerStatePause){
  358. [audioPlayingV stopRotatingImage];
  359. }
  360. [audioPlayingV mas_makeConstraints:^(MASConstraintMaker *make) {
  361. make.height.mas_equalTo(49);
  362. make.left.mas_equalTo(0);
  363. make.right.mas_equalTo(0);
  364. make.bottom.mas_equalTo(-TABBARHEIGHT);
  365. }];
  366. }
  367. #pragma mark 隐藏音频播放中的视图
  368. - (void)hideAudioPlayingViewFun
  369. {
  370. // audioPlayingView * audioPlayingV = [audioPlayingView sharedInstance];
  371. // [audioPlayingV removeFromSuperview];
  372. }
  373. #pragma mark 获取webrct 的链接信息
  374. -(void)queryWebRtcMsgFun:(BOOL)isPlayerType
  375. {
  376. if(isPlayerType){
  377. if(ksharedAppDelegate.DeviceWebRtcMsgMod && ksharedAppDelegate.DeviceWebRtcMsgMod.data.sn){
  378. [self gotoWebRtcVcBy:ksharedAppDelegate.DeviceWebRtcMsgMod];
  379. return;
  380. }
  381. [self showNewIndicatorWithCanBack:YES canTouch:NO];
  382. }
  383. NSMutableDictionary *paraDict = [NSMutableDictionary new];
  384. KWeakSelf
  385. [[netWorkManager shareInstance] CommonPostCallBackCode:webrctQueryByClient Parameters:paraDict success:^(id _Nonnull responseObject){
  386. if(isPlayerType){
  387. [weakSelf removeNewIndicator];
  388. }
  389. webRtcMsgModel *curModel = [[webRtcMsgModel alloc] initWithDictionary:responseObject error:nil];
  390. if(curModel && curModel.status == 0){
  391. ksharedAppDelegate.DeviceWebRtcMsgMod = curModel;
  392. if(isPlayerType){
  393. [weakSelf gotoWebRtcVcBy:curModel];
  394. }
  395. }
  396. else
  397. {
  398. if(isPlayerType && curModel.msg){
  399. [[iToast makeText:curModel.msg] show];
  400. }
  401. }
  402. } failure:^(NSError * _Nonnull error) {
  403. if(isPlayerType){
  404. [weakSelf removeNewIndicator];
  405. [[iToast makeText:NSLocalizedString(@"get_webrtcMsg_fail_tip",nil)] show];
  406. }
  407. }];
  408. }
  409. #pragma mark 跳转webrtc 页面
  410. - (void)gotoWebRtcVcBy:(webRtcMsgModel*)webRtcMsgMod
  411. {
  412. NSArray * vcArrs = self.navigationController.viewControllers;
  413. if(vcArrs.count != 1){
  414. return;
  415. }
  416. [cachesFileManager writeLogsWithMsg:@"webRtcPlayer push webRtcPlayerVC"];
  417. webRtcPlayerViewController *vc = [webRtcPlayerViewController new];
  418. vc.webRtcMsgMod = webRtcMsgMod;
  419. [self.navigationController pushViewController:vc animated:YES];
  420. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  421. ksharedAppDelegate.isCloudPhoneModeNotPrivacyModeOpenType = NO;
  422. ksharedAppDelegate.isCloudPhoneModeAndPrivacyModeOpenType = NO;
  423. ksharedAppDelegate.needToPushWebRtcVCType = NO;
  424. });
  425. }
  426. #pragma mark 输入密码完成
  427. - (void)didInpuPwdOkFun
  428. {
  429. KWeakSelf
  430. mainBlock(^{
  431. if(ksharedAppDelegate.isCloudPhoneModeAndPrivacyModeOpenType
  432. || ksharedAppDelegate.needToPushWebRtcVCType){
  433. [weakSelf queryWebRtcMsgFun:YES];
  434. }
  435. });
  436. }
  437. @end