Today, I upgraded iOS to its latest 11.4. To set system volume, I am using the below method.
-(void) setVolumeLevel:(float)val {
MPVolumeView *slide = [MPVolumeView new];
UISlider *volumeViewSlider;
for (UIView *view in [slide subviews]){
if ([[[view class] description] isEqualToString:@"MPVolumeSlider"]) {
volumeViewSlider = (UISlider *) view;
}
}
volumeViewSlider.value=val;
}
But with 11.4, the volume is not getting set. Below is the log when I print. Please suggest, how to set system volume under iOS 11.4
<MPVolumeSlider: 0x1075bc3f0 dataSource: <MPVolumeControllerSystemDataSource: 0x1075be160 not available>
Try setting up the volume for volumeViewSlider after you start any audio, somehow setting the audiosession to active does not help setting up the volume using MPVolume slider, once the audio starts (using AVAudioPlayer in my case), same code works.
So basically, in my case, after starting the view controller, directly changing the volume using slider does not work, while after starting any audio using AVAudioPlayer in view controller, slider works fine.
Where, volumeSlider is obtained as :