Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

306
Views
Why I can't access .playAndRecord

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.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

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)
    }

}
over 4 years ago · Santiago Trujillo Report

0

you can use 'AVAudioSessionCategoryPlayAndRecord'

over 4 years ago · Santiago Trujillo Report

0

You can refer the code from Apple website. AVAudioSession Apple document

let audioSession = AVAudioSession.sharedInstance()
do {
    try audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord)
} catch {
    print("Setting category to AVAudioSessionCategoryPlayAndRecord failed.")
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!