Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

314
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

0

you can use 'AVAudioSessionCategoryPlayAndRecord'

over 4 years ago · Santiago Trujillo Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda