Avatar ·

Como reproduzir som em um aplicativo iOS em Swift?

Olá a todos! Sou novo no desenvolvimento iOS e estou tentando adicionar efeitos sonoros ao meu aplicativo. Preciso reproduzir um arquivo de som curto (por exemplo, som de clique de botão). Tentei usar AVAudioPlayer, mas algo está errado — o som não é reproduzido ou o aplicativo trava. Aqui está meu código: ```swift import UIKit import AVFoundation class ViewController: UIViewController { var player: AVAudioPlayer? @IBAction func playSound(_ sender: UIButton) { let path = Bundle.main.path(forResource: "sound.mp3", ofType:nil)! let url = URL(fileURLWithPath: path) do { player = try AVAudioPlayer(contentsOf: url) player?.play() } catch { print("Erro de reprodução: \(error.localizedDescription)") } } } ```