| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- //
- // MOVoiceInvitedAlertView.m
- // MiMoLive
- //
- // Created by SuperC on 2024/8/8.
- //
- #import "MOVoiceInvitedAlertView.h"
- #import "MOCreateLiveVC.h"
- #import <AVFoundation/AVFoundation.h>
- @interface MOVoiceInvitedAlertView ()
- @property (weak, nonatomic) IBOutlet UIView *bgView;
- @property (weak, nonatomic) IBOutlet UIImageView *headImgView;
- @property (weak, nonatomic) IBOutlet UILabel *nameLab;
- @property (weak, nonatomic) IBOutlet UIImageView *gradeImgView;
- @property (weak, nonatomic) IBOutlet UILabel *idLab;
- @property (weak, nonatomic) IBOutlet UILabel *tipLab;
- @property (weak, nonatomic) IBOutlet UILabel *contentLab;
- @property (weak, nonatomic) IBOutlet UIButton *rejectBtn;
- @property (weak, nonatomic) IBOutlet UIStackView *theStackView;
- @property (weak, nonatomic) IBOutlet UIButton *videoBtn;
- @property (weak, nonatomic) IBOutlet UIButton *voiceBtn;
- @end
- @implementation MOVoiceInvitedAlertView
- + (instancetype)moVoiceInvitedAlertView{
- return [[[NSBundle mainBundle] loadNibNamed:@"MOVoiceInvitedAlertView" owner:self options:nil] firstObject];
- }
- - (void)awakeFromNib{
- [super awakeFromNib];
-
- self.bgView.layer.cornerRadius = 16.0;
-
- self.headImgView.layer.cornerRadius = 80.0 / 2.0;
- self.headImgView.layer.masksToBounds = YES;
-
- self.videoBtn.layer.cornerRadius = 16.0;
- self.videoBtn.layer.masksToBounds = YES;
- self.videoBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 10);
-
- self.voiceBtn.layer.cornerRadius = 16.0;
- self.voiceBtn.layer.masksToBounds = YES;
- self.voiceBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 10);
-
- self.rejectBtn.layer.cornerRadius = 16.0;
- self.rejectBtn.layer.masksToBounds = YES;
-
- self.tipLab.text = NSLocalString(@"mimo_voice_invite_tip_one");
- self.contentLab.text = NSLocalString(@"mimo_voice_invite_tip_two");
- [self.videoBtn setTitle:NSLocalString(@"mimo_voice_invite_left") forState:UIControlStateNormal];
- [self.voiceBtn setTitle:NSLocalString(@"mimo_voice_invite_right") forState:UIControlStateNormal];
- [self.rejectBtn setTitle:NSLocalString(@"mimo_voice_invite_reject") forState:UIControlStateNormal];
-
- self.nameLab.font = [MOTextTools getTheFontWithSize:20.0 AndFontName:kNormalTitleFontStr];
-
- [self.rejectBtn setFont:[MOTextTools getTheFontWithSize:20.0 AndFontName:kNormalContentFontStr]];
- [self.videoBtn setFont:[MOTextTools getTheFontWithSize:20.0 AndFontName:kNormalContentFontStr]];
- [self.voiceBtn setFont:[MOTextTools getTheFontWithSize:20.0 AndFontName:kNormalContentFontStr]];
- self.idLab.font = [MOTextTools getTheFontWithSize:14.0 AndFontName:kNormalContentFontStr];
- self.tipLab.font = [MOTextTools getTheFontWithSize:16.0 AndFontName:kNormalContentFontStr];
- self.contentLab.font = [MOTextTools getTheFontWithSize:20.0 AndFontName:kNormalContentFontStr];
- }
- - (void)setEntity:(MORtmEntity *)entity{
- _entity = entity;
-
- MORtmJosnEntity *jsonEntity = (MORtmJosnEntity *)entity.data;
-
- [self.headImgView sd_setImageWithURL:[NSURL URLWithString:entity.user.avatar] placeholderImage:[UIImage imageNamed:@"icon_mine_placeHolder"]];
- self.nameLab.text = entity.user.username;
- self.idLab.text = [NSString stringWithFormat:@"ID %zd",entity.user.agoraId];
-
- if(!jsonEntity.camera){
- if([self.theStackView.arrangedSubviews containsObject:self.videoBtn]){
- [self.theStackView removeArrangedSubview:self.videoBtn];
- self.theStackView.spacing = 0.0;
- }
- }
- }
- - (IBAction)videoBtnClick:(id)sender {
- [self toHttpAboutTheInviteWithType:1];
- }
- - (IBAction)voiceBtnClick:(id)sender {
- [self toHttpAboutTheInviteWithType:2];
- }
- - (IBAction)rejectBtnClick:(id)sender {
- [self dismissVoiceInvitedAlertView];
- }
- - (void)toHttpAboutTheInviteWithType:(NSInteger)type{
-
- BOOL isAllowToApply = [self toJudgeTheAuthorized];
- if(!isAllowToApply){
- return;
- }
-
- WEAKSELF
- MORtmJosnEntity *jsonEntity = (MORtmJosnEntity *)self.entity.data;
-
- if(self.roomId.length == 0 || jsonEntity.invite.length == 0){
- return;
- }
-
- NSDictionary *dict = @{@"roomId":self.roomId,
- @"type":@(type),
- @"invite":jsonEntity.invite};
-
- [kHttpManager toAgreedTheLinkMicInviteWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
- if(kCode_Success){
- MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
- MORoomStatus *roomStatusData = [MORoomStatus modelObjectWithDictionary:data[@"data"]];
-
- MOLinkMic *currentMic;
- int x = 1;
- for (MOLinkMic *micObject in roomStatusData.linkMics) {
- if([micObject.profile.id isEqualToString:GetUserId]){
- currentMic = micObject;
- break;
- }
- x ++;
- }
-
- if(currentMic){
- MORtmEntity *entity = [MORtmEntity prepareRtmManageAgreeLianMaiMessageAndLinkMicType:3 AndStatus:7 AndRoomId:weakSelf.roomId AndMOLinkMic:currentMic AndSeatNum:x];
- NSString *entityJsomString = entity.modelToJSONString;
-
- [[MOAgoraRTMManager shareManager] toSendRtmGroupMsg:entityJsomString andBlock:^(BOOL isSuccess) {
- if(isSuccess){
-
- }
- }];
-
- weakSelf.roomStatusChangeBlock ? weakSelf.roomStatusChangeBlock(roomStatusData) : nil;
- }
-
- [weakSelf dismissVoiceInvitedAlertView];
- }
- else{
- MOLogV(@"toAgreedTheLinkMicInviteWithParams 接口报错了");
- kShowNetError(data)
- }
- }];
- }
- - (BOOL)toJudgeTheAuthorized{
-
- BOOL isAllow = YES;
-
- //MARK 检查用户是否对摄像头麦克风授权,未授权不能调用录制功能
- AVAuthorizationStatus videoStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
- AVAuthorizationStatus audioStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio];
-
- //没有打开摄像头权限
- if(videoStatus != AVAuthorizationStatusAuthorized){
- [MOCreateLiveVC requestCameraPermissionWithCompletion:^(BOOL open) {
- if(!open){
- 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];
- [alert show];
- }
- }];
- return NO;
- }
-
- //没有打开麦克风权限
- if(audioStatus != AVAuthorizationStatusAuthorized){
- [MOCreateLiveVC requestAudioPermissionWithCompletion:^(BOOL open) {
- if(!open){
- 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];
- [alert show];
- }
- }];
- return NO;
- }
-
- return YES;
- }
- #pragma mark - UIAlertViewDelegate
- - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
- if (buttonIndex == 1) { // 去设置界面,开启相机访问权限
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
- }
- }
- - (void)showVoiceInvitedAlertView//界面显示动画
- {
-
- UIWindow *keyWindow = [[UIApplication sharedApplication] delegate].window;
- [keyWindow addSubview:self];
- self.frame = CGRectMake(0.0, 0.0, SCREENWIDTH, SCREENHEIGHT);
-
- //动画效果
- self.bgView.transform = CGAffineTransformMakeScale(1.3, 1.3);
- self.bgView.alpha = 0;
- [UIView animateWithDuration:0.2 animations:^
- {
- self.bgView.transform = CGAffineTransformMakeScale(1.0, 1.0);
- self.bgView.alpha = 1;
- } completion:^(BOOL finished)
- {
- }];
- }
- - (void)dismissVoiceInvitedAlertView
- {
- [UIView animateWithDuration:0.2 animations:^
- {
- self.bgView.transform = CGAffineTransformMakeScale(1.3, 1.3);
- self.bgView.alpha = 0;
- } completion:^(BOOL finished)
- {
- if (finished)
- {
- [self removeFromSuperview];
- }
- }];
- }
- @end
|