正在尝试使用AVAudioSession录制音频。但是不能设置类别,以歧义结尾,没有上下文错误。
我用的是swift 4。
@objc func setupRecorder() {
recordingSession = AVAudioSession.sharedInstance()
do {
try recordingSession?.setCategory(.playAndRecord, mode: .default)
try recordingSession.setActive(true)
recordingSession.requestRecordPermission() { [unowned self] allowed in
DispatchQueue.main.async {
if allowed {
self.startRecording()
} else {
// failed to record!
}
}
}
} catch {
// failed to record!
}
}

发布于 2019-07-08 14:26:08
如果您使用的是"Swift4",那么设置类别的方法是不同的,即
AVAudioSession.sharedInstance().setCategory(String, mode: String, options: AVAudioSessionCategoryOptions)ad你可以通过以下方式使用它:
try? AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord, mode: AVAudioSessionModeDefault, options: AVAudioSessionPortBuiltInSpeaker)https://stackoverflow.com/questions/56929214
复制相似问题