Why doesn't ios system sound play in simulator?
I am answering my own question to clarify what I have learned. There were three issues that prevented my original code from working. Note I'm using Xcode6 Beta4, and iphone 5s on the simulator.
1- The original file path I was using of "/System/Library/Audio/UISounds/Tone.caf" does not work in the simulator, it is only valid on the device. Corrected that by adding audio file to the app.
2- Sound not working in iPhone Simulator? provided information that got sound working for ios 7.1 and earlier. Not sure which of the several suggestions worked since I was testing with ios8 as I ran through them.
3- Because the same code that works on ios7 doesn't work on ios8, I am assuming there is a bug in the io8 simulator code (ios8 device works OK). Out of three ways I have tried to produce sound, only one doesn't work:
AudioServicesPlaySystemSound() - doesn't work
AudioUnit output - works
AVAudioPlayer - works
Because file does not exist at the path you specified. To test this, save an sound file on your local and specify its path your code (See e.g. below) -
let fileURL = NSURL(fileURLWithPath: "/Users/<Home dir>/Desktop/yoursund.mp3")