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)     } } 

enter image description here

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

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -