How to change the volume in iOS9?

This code works fine in iOS 8.0 devices, but in iOS 9.0 always getting slider value as 0.000...


- (void) volumeUp{

    MPVolumeView* volumeView = [[MPVolumeView alloc] init];

    UISlider* volumeViewSlider = nil;
    for (UIView *view in [volumeView subviews]){
        if ([view.class.description isEqualToString:@"MPVolumeSlider"]){
            volumeViewSlider = (UISlider*)view; // volumeViewSlider always 0.000
            break;
        }
    }

    [volumeViewSlider setValue:[volumeViewSlider value] + 0.0625 animated:YES];
    [volumeViewSlider sendActionsForControlEvents:UIControlEventTouchUpInside];

}


How can I fix it? I need to turn up the volume 0.0625 each time.


Thanks!

Replies

Relying on undocumented ways of performing a specific task is never a good thing. Changing the output volume on a user without their knowledge is also never a good thing. If you require some functionality that is not provided via a supportable exposed API please file a bug asking for the specific feature.


Also discussed here:

https://forums.developer.apple.com/message/43236