gpt4 book ai didi

swift - AVCaptureDevice.requestAccess(for:.audio)不会提示用户,并且返回true。可能吗?

转载 作者:行者123 更新时间:2023-12-03 01:21:20 24 4
gpt4 key购买 nike

我需要提示用户音频许可,以便在我的iOS项目中进一步使用WebRTC。我已将NSMicrophoneUsageDescription添加到info.plist并尝试遵循以下代码,但即使AVCaptureDevice.authorizationStatus(for:.audio)为.notDetermined,也无法正常工作。

AVCaptureDevice.requestAccess(for:.audio)不会提示用户,而是突然返回true。

XCode 11.1,Swift 5,iPhone 8 Plus 11.0.1模拟器

switch AVCaptureDevice.authorizationStatus(for: .audio) {
case .authorized:
self.doSmt()

case .notDetermined:
AVCaptureDevice.requestAccess(for: .audio) { granted in
if granted {
self.doSmt() // Works immediately without promting user.
}
}

case .denied:
return

case .restricted:
return
}

最佳答案

official documentation和此old answer的最后一行所述,AVCaptureDevice.requestAccess(for:.audio)或AVAudioSession.sharedInstance()。requestRecordPermission会在模拟器上执行 NOT 的工作,并且始终返回真实的“授权”。

Invoking this method with audio is equivalent to calling the AVAudioSession method requestRecordPermission(_:).


问题解决了。

关于swift - AVCaptureDevice.requestAccess(for:.audio)不会提示用户,并且返回true。可能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61149684/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com