PlayerViewController+AppDelegate.m 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. //
  2. // CloudPhoneViewController+RBDConnect.m
  3. // VclustersGemini
  4. //
  5. // Created by APPLE on 2021/8/16.
  6. // Copyright © 2021 APPLE. All rights reserved.
  7. //
  8. #import "PlayerViewController+AppDelegate.h"
  9. #import "AppDelegate.h"
  10. #import <SystemConfiguration/CaptiveNetwork.h>
  11. #import <RCCloudPhoneSDK/RCAudioPlayer.h>
  12. #import "ShortcutManager.h"
  13. #import <objc/runtime.h>
  14. #import "RCCommandHelp.h"
  15. #import "PlayerViewController+otherDelegate.h"
  16. //@interface PlayerViewController(AppDelegate)
  17. //
  18. //@end
  19. @implementation PlayerViewController(AppDelegate)
  20. @dynamic nowSSid;
  21. - (void)setNowSSid:(NSString *)nowSSid {
  22. objc_setAssociatedObject(self, @selector(nowSSid), nowSSid, OBJC_ASSOCIATION_COPY);
  23. }
  24. - (NSString *)nowSSid {
  25. return objc_getAssociatedObject(self, @selector(nowSSid));
  26. }
  27. #pragma mark - UIApplication Delegate
  28. - (void)applicationWillResignActive:(NSNotification *)notification
  29. {
  30. self.nowSSid = [self observeWiFi];
  31. if (USEAAC)
  32. {
  33. if (aacPlayer)
  34. {
  35. [aacPlayer stop];
  36. aacPlayer = nil;
  37. }
  38. }
  39. [self setShowImgAndVoiceTypeFun:NO];
  40. }
  41. - (void)applicationDidEnterBackground:(NSNotification *)notification {
  42. // 当前控制器是PlayerViewController app进入后台时 移除alert
  43. UIViewController *currentVC = [[ShortcutManager shareInstance] findCurrentShowingViewController];
  44. if ([currentVC isKindOfClass:[UIAlertController class]]) {
  45. UIAlertController *alertVC = (UIAlertController *)currentVC;
  46. NSMutableAttributedString *attriMsg = [alertVC valueForKey:@"_attributedMessage"];
  47. if ([attriMsg.string containsString:@"授权方已收回控制权,您进入观看屏幕模式。"] ||
  48. [attriMsg.string containsString:@"当前云手机正在受控,是否请求获取云手机控制权?"] ||
  49. [attriMsg.string containsString:@"当前云手机正在受控,进入云手机后,只能预览屏幕"]) {
  50. return;
  51. }
  52. [currentVC dismissViewControllerAnimated:NO completion:nil];
  53. }
  54. self.needToDissconnectType = YES;
  55. [self disconnectVideoServer];
  56. HLog(@"开始进入后台");
  57. //[cachesFileManager writeLogsWithMsg:@"EnterBackground"];
  58. }
  59. - (void)applicationDidBecomeActive:(NSNotification *)notification
  60. {
  61. NSString *tempSSID = [self observeWiFi];
  62. self.nowSSid = tempSSID;
  63. if ([wattingView superview])
  64. {
  65. [self removeNewIndicator];
  66. [self showNewIndicator];
  67. }
  68. if (![tempSSID isEqualToString:self.nowSSid] && ![@"<<NONE>>" isEqualToString:tempSSID] && ![@"<<NONE>>" isEqualToString:self.nowSSid])
  69. {
  70. [self showNewIndicator];
  71. [self tryAgain];
  72. return;
  73. }
  74. if(self.needToDissconnectType){
  75. self.needToDissconnectType = NO;
  76. [self tryAgain];
  77. }
  78. else{
  79. [self requestIFrame];
  80. }
  81. [self setShowImgAndVoiceTypeFun:YES];
  82. [self updateCopydata];
  83. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  84. [self checkFullScreenWithTVShowStateFun];
  85. });
  86. }
  87. - (void)applicationWillTerminate:(UIApplication *)application {
  88. // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
  89. [self disconnectVideoServer];
  90. }
  91. - (NSString *)observeWiFi{
  92. NSString *currentSSID = @"Not Found";
  93. CFArrayRef myArray = CNCopySupportedInterfaces();
  94. if (myArray != nil){
  95. NSDictionary* myDict = (__bridge NSDictionary *)CNCopyCurrentNetworkInfo((CFStringRef)CFArrayGetValueAtIndex(myArray,0));
  96. if (myDict!=nil){
  97. currentSSID=[myDict valueForKey:@"SSID"];
  98. } else {
  99. currentSSID=@"<<NONE>>";
  100. }
  101. } else {
  102. currentSSID=@"<<NONE>>";
  103. }
  104. if (myArray)
  105. {
  106. CFRelease(myArray);
  107. }
  108. return currentSSID;
  109. }
  110. - (void)updateCopydata{
  111. UIPasteboard* pasteboard = [UIPasteboard generalPasteboard];
  112. NSString *str = [pasteboard string];
  113. HLog(@"__________%s______%@____",__func__,str);
  114. if ([str rangeOfString:@"CVLUSTERS_NOUSE_"].location != NSNotFound)
  115. {
  116. str = nil;
  117. }
  118. if (str && str.length >0)
  119. {
  120. //HLog(@"hxd111 cutting %@",str);
  121. /*发送数据*/
  122. NSString *dataStr = [RCCommandHelp commandCuttingWithContent:str];
  123. [[webSocketManager shareInstance] send_data:dataStr];
  124. //pasteboard.string = @"";
  125. }
  126. }
  127. #pragma mark 全面屏与TV投屏逻辑交互
  128. - (void)checkFullScreenWithTVShowStateFun
  129. {
  130. BOOL isTVShowType = ksharedAppDelegate.TvStatusMod.isTVShowType;
  131. BOOL fullscreenType = [HWDataManager getBoolWithKey:Consn_player_full_screen_show];
  132. if(isTVShowType && fullscreenType){//关闭全屏屏
  133. [HWDataManager setBoolWithKey:Consn_player_full_screen_show value:NO];
  134. fullscreenType = NO;
  135. //通知界面修改UI
  136. [[NSNotificationCenter defaultCenter] postNotificationName:setPlayerFullScreenNotification object:nil];
  137. }
  138. //重新设置分辨率
  139. if(fullscreenType){
  140. NSString *commandStr = [RCCommandHelp commondToSetFullScreenPhoneSize];
  141. [[webSocketManager shareInstance] send_data:commandStr];
  142. }
  143. else{
  144. if ((ksharedAppDelegate.couldPhone_W_PHONE == 720 && ksharedAppDelegate.couldPhone_H_PHONE == 1280)
  145. || (ksharedAppDelegate.couldPhone_W_PHONE == 1080 && ksharedAppDelegate.couldPhone_H_PHONE == 1920)) {//云机可能存在的分辨率
  146. }
  147. else{
  148. NSString *commondStr = [RCCommandHelp setPhoneSizecommandWithWidth:1080 high:1920 dpi:480];
  149. //NSString *commondStr = @"{\"data\":{\"height\":1920,\"width\":1080},\"type\":\"setPhoneSize\"}";
  150. [[webSocketManager shareInstance] send_data:commondStr];
  151. }
  152. }
  153. }
  154. @end