我以前可以使用以下代码播放系统音频文件。对于新旧应用程序,这在iOS 13中均不起作用。
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
}
我也看不到“音频反馈错误”字样。
是否可以在iOS 13中播放简单的声音?
答案 0 :(得分:0)
这有效:
AudioServicesPlaySystemSound(SystemSoundID(1104))
此处提供所有系统声音的列表:https://github.com/TUNER88/iOSSystemSoundsLibrary