【问题标题】:Don't ask for mic permission不要要求麦克风许可
【发布时间】:2018-03-21 08:29:07
【问题描述】:

我正在开发一个 WebRTC iOS 应用程序来接收来自网络摄像头的视频/音频流。

设备只接收音视频流,不采集音视频,所以不需要申请麦克风权限。

如何禁止申请麦克风权限? @kemmitorz

我已经删除了以下方法,但没有解决问题。

- (RTCRtpSender *)createAudioSender 
{ 
    RTCMediaConstraints *constraints = [self defaultMediaAudioConstraints]; 
    RTCAudioSource *source = [_factory audioSourceWithConstraints:constraints]; 
    RTCAudioTrack *track = [_factory audioTrackWithSource:source 
                                                  trackId:kARDAudioTrackId]; 
    RTCRtpSender *sender = [_peerConnection 
                           senderWithKind:kRTCMediaStreamTrackKindAudio 
                                 streamId:kARDMediaStreamId]; 
    sender.track = track; 
    return sender;
 }

如果我将 OfferToReceiveAudio 设置为 false。设备不会申请麦克风权限。但是接收到的视频没有声音。

- (RTCMediaConstraints )defaultOfferConstraints 
{ 
    NSDictionary *mandatoryConstraints = @{ 
                                            @"OfferToReceiveAudio" : @"true", 
                                            @"OfferToReceiveVideo" : @"true" 
                                          };
    RTCMediaConstraints constraints = [[RTCMediaConstraints alloc] 
                                 initWithMandatoryConstraints:mandatoryConstraints 
                                          optionalConstraints:nil]; 
    return constraints;
 } 

【问题讨论】:

  • 您是否在 info.plist 文件中添加了权限
  • 是的,我做到了。如果我不这样做,应用程序将会崩溃。
  • 检查我的答案

标签: ios webrtc microphone


【解决方案1】:

录制音频需要用户的明确许可。首先 应用的音频会话尝试使用音频输入路由的时间 使用启用录制的类别时(请参阅“音频会话 类别”),系统会自动提示用户输入 允许;或者,您可以调用 requestRecordPermission: 来 在您选择的时间提示用户

switch ([[AVAudioSession sharedInstance] recordPermission]) {
    case AVAudioSessionRecordPermissionGranted:
        // here call your record method and put this condition in your viewcontroller.
        break;
    case AVAudioSessionRecordPermissionDenied:

        break;
    case AVAudioSessionRecordPermissionUndetermined:
        // This is the initial state before a user has made any choice
        // You can use this spot to request permission here if you want
        break;
    default:
        break;
}

快乐编码..

有什么问题请告诉我。

【讨论】:

  • 我想禁用麦克风权限对话框,因为我不需要这个权限。不知道webrtc建立连接过程的哪一步会申请麦克风权限。谢谢
  • @loveDoudou 我认为这个链接会对你有所帮助。 script-tutorials.com/step-by-step-webrtc
猜你喜欢
  • 2018-03-20
  • 1970-01-01
  • 1970-01-01
  • 2019-11-04
  • 2019-06-07
  • 1970-01-01
  • 2019-08-28
  • 1970-01-01
  • 2019-03-27
相关资源
最近更新 更多