ios - Button On/Off sound in settings -
i have 2 viewcontroller (viewcontroller , settings). how can when switch turned off sound of buttons (or in application) turned off , turned on ??
code sound of buttons:
@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 cfurl, &soundid) audioservicesaddsystemsoundcompletion(soundid, nil, nil, { (soundid, clientdata) -> void in audioservicesdisposesystemsoundid(soundid) }, nil) audioservicesplaysystemsound(soundid) } }
take global boolean variable issound uiswitch. when uiswitch on means true, make variable issound on. now, make condition based on variable.
you can make global variable appdelegate file or header file. (.h file)
if issound == true || issound == on { // make sound on } else { // make sound off } 
Comments
Post a Comment