No audio on local device build

I built a simple Swift game in SpriteKit. I have audio on the simulator but no audio or sound effects on the device. Any suggestions?

Accepted Reply

Solved: I had my silent mode switch on. This is interesting since I would get audio from other apps but not the local build.

Replies

Solved: I had my silent mode switch on. This is interesting since I would get audio from other apps but not the local build.
You can control whether sound plays or doesn't play when the silent mode switch is on. Configure your AVAudioSession to use a suitable category:

https://developer.apple.com/documentation/avfoundation/avaudiosession
https://developer.apple.com/documentation/avfoundation/avaudiosession/1771734-setcategory
https://developer.apple.com/library/archive/documentation/Audio/Conceptual/AudioSessionProgrammingGuide/AudioSessionCategoriesandModes/AudioSessionCategoriesandModes.html

(That last one is a legacy document, but I believe it's still correct about the interaction between category and silent switch.)

If I hadn't found this I'm not sure how long I would've been stuck since I typically keep my silent switch turned on all the time. Thank you and for me the issue was specifically related to needing to use the playback property which I'll link below:

https://developer.apple.com/documentation/avfaudio/avaudiosession/category/1616509-playback