Reputation: 1130
I used to be able to play system audio files using the code below. This is not working in iOS 13 for both old and new applications.
import AudioToolbox
import AVFoundation
...
func tock() {
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category(rawValue: convertFromAVAudioSessionCategory(AVAudioSession.Category.ambient)))
var myAlertSound: SystemSoundID = 0
let url: URL = URL(string: "/System/Library/Audio/UISounds/Tock.caf")!
AudioServicesCreateSystemSoundID( (url) as CFURL, &myAlertSound)
AudioServicesPlaySystemSound(myAlertSound)
} catch {
print("Error in audio feedback")
}
}
// Helper function inserted by Swift 4.2 migrator.
private func convertFromAVAudioSessionCategory(_ input: AVAudioSession.Category) -> String {
return input.rawValue
}
I don't see the "Error in audio feedback" print either.
Is there a way to play simple sounds in iOS 13?
Upvotes: 2
Views: 4290
Reputation: 1130
This worked:
AudioServicesPlaySystemSound(SystemSoundID(1104))
The list of all system sounds is available here: https://github.com/TUNER88/iOSSystemSoundsLibrary
Upvotes: 6