IOS code to modify the volume
Recently, in a project, the user needs to automatically adjust the volume to a certain value after opening the APP. So I studied it.
I have previously done research on iOS sound. Apple has strict control over iPhone input/output, because Apple wants to control user experience consistency. For example, when a user pulls out the headset, Apple believes that the user does not want others to know what he is listening, so the voice will be automatically paused at this time. Apple also adopted a similar strategy in terms of volume adjustment. Apple believes that users do not need an APP to specify the volume for them, because sometimes users may feel uncomfortable. This is what Apple's development documentation says:
You cannot change device volume programatically,however MPVolumeView (volume slider) is there to change device volume but only through user interaction.
Apple provides a method for users to manually modify the volume: MPVolumeView. You can drag the slider bar to modify the volume, which is the following:
Although Apple blocks almost all the methods for controlling the volume of code, some private methods can still be modified. For example, we traverse the subViews of the MPVolumeView, obtain the UISlider, and modify the value of the slider. Although this method can be modified, accessing a private class poses a risk of being rejected by the App Store. I don't know when Apple will modify the structure of MPVolumeView. This method won't work. <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + crop/crop + 8/crop + crop = "brush: java;"> MPMusicPlayerController * musicController = [MPMusicPlayerController applicationMusicPlayer]; musicController. volume = 0.2;
You need to add MediaPlayer. framework before using it.
Why can't I get rid of apple if I want to get rid of it? This method was added in iOS3.0. At that time, it was estimated that there was no such specification as "do not allow the use of code to modify the volume". Later, at 7.0, this method was depress, this means that Apple is trying to get rid of it. But for a continuous improvement system, it is generally to be forward compatible, otherwise there will be a tragedy like WP6-WP7-WP8. Therefore, Apple is very cautious about removing a method, and finally keeps this method, leaving a window for development in its powerful wall.