MOVoiceInvitedAlertView.m 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. //
  2. // MOVoiceInvitedAlertView.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2024/8/8.
  6. //
  7. #import "MOVoiceInvitedAlertView.h"
  8. #import "MOCreateLiveVC.h"
  9. #import <AVFoundation/AVFoundation.h>
  10. @interface MOVoiceInvitedAlertView ()
  11. @property (weak, nonatomic) IBOutlet UIView *bgView;
  12. @property (weak, nonatomic) IBOutlet UIImageView *headImgView;
  13. @property (weak, nonatomic) IBOutlet UILabel *nameLab;
  14. @property (weak, nonatomic) IBOutlet UIImageView *gradeImgView;
  15. @property (weak, nonatomic) IBOutlet UILabel *idLab;
  16. @property (weak, nonatomic) IBOutlet UILabel *tipLab;
  17. @property (weak, nonatomic) IBOutlet UILabel *contentLab;
  18. @property (weak, nonatomic) IBOutlet UIButton *rejectBtn;
  19. @property (weak, nonatomic) IBOutlet UIStackView *theStackView;
  20. @property (weak, nonatomic) IBOutlet UIButton *videoBtn;
  21. @property (weak, nonatomic) IBOutlet UIButton *voiceBtn;
  22. @end
  23. @implementation MOVoiceInvitedAlertView
  24. + (instancetype)moVoiceInvitedAlertView{
  25. return [[[NSBundle mainBundle] loadNibNamed:@"MOVoiceInvitedAlertView" owner:self options:nil] firstObject];
  26. }
  27. - (void)awakeFromNib{
  28. [super awakeFromNib];
  29. self.bgView.layer.cornerRadius = 16.0;
  30. self.headImgView.layer.cornerRadius = 80.0 / 2.0;
  31. self.headImgView.layer.masksToBounds = YES;
  32. self.videoBtn.layer.cornerRadius = 16.0;
  33. self.videoBtn.layer.masksToBounds = YES;
  34. self.videoBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 10);
  35. self.voiceBtn.layer.cornerRadius = 16.0;
  36. self.voiceBtn.layer.masksToBounds = YES;
  37. self.voiceBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 10);
  38. self.rejectBtn.layer.cornerRadius = 16.0;
  39. self.rejectBtn.layer.masksToBounds = YES;
  40. self.tipLab.text = NSLocalString(@"mimo_voice_invite_tip_one");
  41. self.contentLab.text = NSLocalString(@"mimo_voice_invite_tip_two");
  42. [self.videoBtn setTitle:NSLocalString(@"mimo_voice_invite_left") forState:UIControlStateNormal];
  43. [self.voiceBtn setTitle:NSLocalString(@"mimo_voice_invite_right") forState:UIControlStateNormal];
  44. [self.rejectBtn setTitle:NSLocalString(@"mimo_voice_invite_reject") forState:UIControlStateNormal];
  45. self.nameLab.font = [MOTextTools getTheFontWithSize:20.0 AndFontName:kNormalTitleFontStr];
  46. [self.rejectBtn setFont:[MOTextTools getTheFontWithSize:20.0 AndFontName:kNormalContentFontStr]];
  47. [self.videoBtn setFont:[MOTextTools getTheFontWithSize:20.0 AndFontName:kNormalContentFontStr]];
  48. [self.voiceBtn setFont:[MOTextTools getTheFontWithSize:20.0 AndFontName:kNormalContentFontStr]];
  49. self.idLab.font = [MOTextTools getTheFontWithSize:14.0 AndFontName:kNormalContentFontStr];
  50. self.tipLab.font = [MOTextTools getTheFontWithSize:16.0 AndFontName:kNormalContentFontStr];
  51. self.contentLab.font = [MOTextTools getTheFontWithSize:20.0 AndFontName:kNormalContentFontStr];
  52. }
  53. - (void)setEntity:(MORtmEntity *)entity{
  54. _entity = entity;
  55. MORtmJosnEntity *jsonEntity = (MORtmJosnEntity *)entity.data;
  56. [self.headImgView sd_setImageWithURL:[NSURL URLWithString:entity.user.avatar] placeholderImage:[UIImage imageNamed:@"icon_mine_placeHolder"]];
  57. self.nameLab.text = entity.user.username;
  58. self.idLab.text = [NSString stringWithFormat:@"ID %zd",entity.user.agoraId];
  59. if(!jsonEntity.camera){
  60. if([self.theStackView.arrangedSubviews containsObject:self.videoBtn]){
  61. [self.theStackView removeArrangedSubview:self.videoBtn];
  62. self.theStackView.spacing = 0.0;
  63. }
  64. }
  65. }
  66. - (IBAction)videoBtnClick:(id)sender {
  67. [self toHttpAboutTheInviteWithType:1];
  68. }
  69. - (IBAction)voiceBtnClick:(id)sender {
  70. [self toHttpAboutTheInviteWithType:2];
  71. }
  72. - (IBAction)rejectBtnClick:(id)sender {
  73. [self dismissVoiceInvitedAlertView];
  74. }
  75. - (void)toHttpAboutTheInviteWithType:(NSInteger)type{
  76. BOOL isAllowToApply = [self toJudgeTheAuthorized];
  77. if(!isAllowToApply){
  78. return;
  79. }
  80. WEAKSELF
  81. MORtmJosnEntity *jsonEntity = (MORtmJosnEntity *)self.entity.data;
  82. if(self.roomId.length == 0 || jsonEntity.invite.length == 0){
  83. return;
  84. }
  85. NSDictionary *dict = @{@"roomId":self.roomId,
  86. @"type":@(type),
  87. @"invite":jsonEntity.invite};
  88. [kHttpManager toAgreedTheLinkMicInviteWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  89. if(kCode_Success){
  90. MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
  91. MORoomStatus *roomStatusData = [MORoomStatus modelObjectWithDictionary:data[@"data"]];
  92. MOLinkMic *currentMic;
  93. int x = 1;
  94. for (MOLinkMic *micObject in roomStatusData.linkMics) {
  95. if([micObject.profile.id isEqualToString:GetUserId]){
  96. currentMic = micObject;
  97. break;
  98. }
  99. x ++;
  100. }
  101. if(currentMic){
  102. MORtmEntity *entity = [MORtmEntity prepareRtmManageAgreeLianMaiMessageAndLinkMicType:3 AndStatus:7 AndRoomId:weakSelf.roomId AndMOLinkMic:currentMic AndSeatNum:x];
  103. NSString *entityJsomString = entity.modelToJSONString;
  104. [[MOAgoraRTMManager shareManager] toSendRtmGroupMsg:entityJsomString andBlock:^(BOOL isSuccess) {
  105. if(isSuccess){
  106. }
  107. }];
  108. weakSelf.roomStatusChangeBlock ? weakSelf.roomStatusChangeBlock(roomStatusData) : nil;
  109. }
  110. [weakSelf dismissVoiceInvitedAlertView];
  111. }
  112. else{
  113. MOLogV(@"toAgreedTheLinkMicInviteWithParams 接口报错了");
  114. kShowNetError(data)
  115. }
  116. }];
  117. }
  118. - (BOOL)toJudgeTheAuthorized{
  119. BOOL isAllow = YES;
  120. //MARK 检查用户是否对摄像头麦克风授权,未授权不能调用录制功能
  121. AVAuthorizationStatus videoStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
  122. AVAuthorizationStatus audioStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio];
  123. //没有打开摄像头权限
  124. if(videoStatus != AVAuthorizationStatusAuthorized){
  125. [MOCreateLiveVC requestCameraPermissionWithCompletion:^(BOOL open) {
  126. if(!open){
  127. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalString(@"mimo_get_video_authority_fail_tip") message:NSLocalString(@"mimo_get_video_authority_fail_content_tip") delegate:self cancelButtonTitle:NSLocalString(@"mimo_get_video_authority_normal_sure") otherButtonTitles:NSLocalString(@"mimo_get_video_authority_go_sure"), nil];
  128. [alert show];
  129. }
  130. }];
  131. return NO;
  132. }
  133. //没有打开麦克风权限
  134. if(audioStatus != AVAuthorizationStatusAuthorized){
  135. [MOCreateLiveVC requestAudioPermissionWithCompletion:^(BOOL open) {
  136. if(!open){
  137. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalString(@"mimo_get_audio_authority_fail_tip") message:NSLocalString(@"mimo_get_audio_authority_fail_content_tip") delegate:self cancelButtonTitle:NSLocalString(@"mimo_get_video_authority_normal_sure") otherButtonTitles:NSLocalString(@"mimo_get_video_authority_go_sure"), nil];
  138. [alert show];
  139. }
  140. }];
  141. return NO;
  142. }
  143. return YES;
  144. }
  145. #pragma mark - UIAlertViewDelegate
  146. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
  147. if (buttonIndex == 1) { // 去设置界面,开启相机访问权限
  148. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
  149. }
  150. }
  151. - (void)showVoiceInvitedAlertView//界面显示动画
  152. {
  153. UIWindow *keyWindow = [[UIApplication sharedApplication] delegate].window;
  154. [keyWindow addSubview:self];
  155. self.frame = CGRectMake(0.0, 0.0, SCREENWIDTH, SCREENHEIGHT);
  156. //动画效果
  157. self.bgView.transform = CGAffineTransformMakeScale(1.3, 1.3);
  158. self.bgView.alpha = 0;
  159. [UIView animateWithDuration:0.2 animations:^
  160. {
  161. self.bgView.transform = CGAffineTransformMakeScale(1.0, 1.0);
  162. self.bgView.alpha = 1;
  163. } completion:^(BOOL finished)
  164. {
  165. }];
  166. }
  167. - (void)dismissVoiceInvitedAlertView
  168. {
  169. [UIView animateWithDuration:0.2 animations:^
  170. {
  171. self.bgView.transform = CGAffineTransformMakeScale(1.3, 1.3);
  172. self.bgView.alpha = 0;
  173. } completion:^(BOOL finished)
  174. {
  175. if (finished)
  176. {
  177. [self removeFromSuperview];
  178. }
  179. }];
  180. }
  181. @end