I have multiple sounds in my application. I want to setup a toggle switch in settings to turn these sounds off. Here is the code that executes the sounds.
- (void) soundEventDidHappen:(NSString*)eventName {
//check dictionary of sounds.. if there is a corresponding sound for this event name, play it
if ([[soundIDForEventString allKeys] containsObject:eventName]) {
AudioServicesPlaySystemSound ([[soundIDForEventString objectForKey:eventName] intValue]);
}
You could make a simple toggle like this:
and then you could just do:
Which will play the sound if
isToggled
is true. You could then useNSUserDefaults
if you would like to save the boolean for the future:Then you could use this to get the value (most likely somewhere in your
viewDidLoad
method: