AVCaptureDevice.requestAccess(for: .audio) 不提示用户并且 returns 为真。可能吗?

AVCaptureDevice.requestAccess(for: .audio) does NOT prompt to user and returns true. Is it possible?

我需要提示用户提供音频权限,以便在我的 iOS 项目中进一步使用 WebRTC。我已将 NSMicrophoneUsageDescription 添加到 info.plist 并尝试遵循代码,但即使 AVCaptureDevice.authorizationStatus(for: .audio) is .notDetermined.

也无法正常工作

AVCaptureDevice.requestAccess(for: .audio) 不提示用户,突然 returns 为真。

XCode11.1,Swift5,iPhone8 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, and this old answer、AVCaptureDevice.requestAccess(对于:.audio)或 AVAudioSession.sharedInstance() 的最后一行所述。requestRecordPermission NOT 在 Simulator 上工作并且总是 returns true aka "granted".

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

问题已解决。