0

I searched the solution for hours and it seems that AVSystemController_SystemVolumeDidChangeNotification should work. But after I finished the code I didn't see any callback when pressing the volume button. Here is my code:

@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(volumeChanged:)
                                             name:@"AVSystemController_SystemVolumeDidChangeNotification"
                                           object:nil];
NSLog(@"init finished");
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (void)volumeChanged:(NSNotification *)notification
{

float volume =
[[[notification userInfo]
  objectForKey:@"AVSystemController_AudioVolumeNotificationParameter"]
 floatValue];

NSLog(@"current volume = %f", volume);

}

0 Answers0