1

When i press volume button three times its need to show notification. i want to integrate this feature in my app.

Any help will be appreciated.Thanks in advance.

Jamshed Alam
  • 12,424
  • 5
  • 26
  • 49
NilamPari
  • 79
  • 8

1 Answers1

1

First, you initialise the AVAudioSession and add a listener by:

AVAudioSession* audioSession = [AVAudioSession sharedInstance];
[audioSession setActive:YES error:nil];
[audioSession addObserver:self
                   forKeyPath:@"outputVolume"
                      options:0
                      context:nil];

Then you store the current system volume by:

float currentVolume = [audioSession outputVolume];

Then observe the volume change notification:

-(void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
    if ([keyPath isEqual:@"outputVolume"]) {
        float newVolume = [[AVAudioSession sharedInstance] outputVolume];
    }
}

You compare the newVolume and the currentVolume to determine the expected outcome.

The Mach System
  • 6,703
  • 3
  • 16
  • 20