How can I execute a method when the volume button is pressed?

373 views Asked by At

I am trying to execute a method when the user presses the volume button but the "volumeChanged" line does not appear in the logs. I looked at several examples

iPhone Detect Volume Keys press.

iOS Detect system volume level change. private API or not? AVSystemController_SystemVolumeDidChangeNotification

-(void)volumeChanged{
    //do something
    NSLog(@"volumeChanged");
}

- (void)viewDidLoad {
    [super viewDidLoad];
    masterViewController = self;
    [masterViewController swipeInit];
    [masterViewController intervalPickerInit];

    // init audio session
    AudioSessionInitialize(NULL, NULL, NULL, NULL);
    AudioSessionSetActive(true);

    [[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(volumeChanged:)
                                             name:@"AVSystemController_SystemVolumeDidChangeNotification"
                                           object:nil];
0

There are 0 answers