MPMusicPlayerController setVolume is deprecated since iOS 7
Is there any other way to change system music volume? Preferably without user interaction. Its important feature: to increase volume automatically for any alarm clock from AppStore.
To answer you question exactly: Yes there is other way to change system volume without user interaction.
Until recent times I used to think that changing volume using MPVolumeView programmatically is possible only using private API. But I have just verified, that changing the value of volumeSlider and faking slider's touchUP event works:
MPVolumeView* volumeView = [[MPVolumeView alloc] init]; //find the volumeSlider UISlider* volumeViewSlider = nil; for (UIView *view in [volumeView subviews]){ if ([view.class.description isEqualToString:@"MPVolumeSlider"]){ volumeViewSlider = (UISlider*)view; break; } } [volumeViewSlider setValue:1.0f animated:YES]; [volumeViewSlider sendActionsForControlEvents:UIControlEventTouchUpInside];
(When slider receives touchUP event, it will invoke _commitVolumeChange
method on itself, which will change the system volume)
Until Apple sees fit to rescind this decision there are two remedies I have discovered:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With