我有两个ViewController(ViewController和Settings)。我怎么能做到这一点,当关闭开关的按钮(或在应用程序)的声音被关闭和打开?按钮开/关设置中的声音
代码按钮的声音:
@IBAction func SoundButton(_ sender: UIButton) {
let filename = "button-16"
let ext = "mp3"
if let soundUrl = Bundle.main.url(forResource: filename, withExtension: ext) {
var soundId: SystemSoundID = 0
AudioServicesCreateSystemSoundID(soundUrl as CFURL, &soundId)
AudioServicesAddSystemSoundCompletion(soundId, nil, nil, { (soundId, clientData) -> Void in
AudioServicesDisposeSystemSoundID(soundId)
}, nil)
AudioServicesPlaySystemSound(soundId)
}
}
很抱歉,但我不明白的问题,可以更详细地描述? –
@AnhPham当开关关闭时,必须关闭按钮的声音 – KVL