I'm trying to play a sound in Swift 4 iOS 12 with Xcode 10. I have a project where I already did that and I'm copying the code from that project.
But now when executing the following code:
try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playAndRecord, mode: .default)
I get the following error in this exact line:
Type 'AVAudioSession.Category' (aka 'NSString') has no member 'playAndRecord'
I already imported AVFoundation so I have no idea is not working.
I face the same issue, I was working in swift v4 and the code you are using is for Swift 4.2 You have to use the following string AVAudioSessionCategoryPlayAndRecord in place of playAndRecord
let audioSession = AVAudioSession.sharedInstance()
do {
try audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord, mode: AVAudioSessionModeVoiceChat, options: AVAudioSessionCategoryOptions.mixWithOthers)
try audioSession.overrideOutputAudioPort(.none)
try audioSession.setActive(true)
} catch {
debugPrint(error.localizedDescription)
}
}
you can use 'AVAudioSessionCategoryPlayAndRecord'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With