0
按下此按钮时使用此代码按下按钮。打开/关闭声音(IOS)
是否可以这样做,当您关闭“开关”(位于第二个VC上)时,第一个VC上的按钮的声音会关闭?
@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)
}
}