cloudPhoneViewController.m 18 KB

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