Recently in a project, you need the user to open the app, automatically adjust the volume to a value, and then studied a bit.
Before doing research on iOS sound, apple controls the input/output of iphone devices very tightly, because Apple controls the consistency of the user experience. For example: When the user pulls the headset down, Apple believes that the user does not want others to know what they are listening to, and then the voice is automatically paused. On the volume adjustment, Apple also adopted a similar strategy. Apple believes that the user does not need the app to specify the volume for him, because sometimes users feel uncomfortable. That's what Apple's development documentation says:
You cannot change device volume Programatically,however mpvolumeview (volume slider) are there to change device volume Only through user interaction.
Apple provides a way for users to manually modify the volume: Mpvolumeview. The user modifies the volume by dragging the slider bar, which is the following:
While Apple has blocked almost all of the code's way of controlling the volume, it can be modified with some proprietary methods. For example, we iterate over the subviews of Mpvolumeview, get uislider from it, and then modify the value of the slider. Although this approach can be modified, access to private classes has the risk of being rejected by the App Store. And do not know when Apple modifies the structure of the mpvolumeview, such a method is not.
Here is a small trick that can modify the volume, an Apple's way to kill it:
mpmusicplayercontroller* Musiccontroller = [Mpmusicplayercontroller applicationmusicplayer];musiccontroller.volume = 0.2;
You need to add mediaplayer.framework before using.
Why is it that Apple wants to kill and can't kill it? This method was added to the iOS3.0, when it was estimated that there was no "do not allow code to modify the volume" specification; later, at 7.0, the method was depress out, indicating that Apple wanted to kill it. But for a continuous improvement of the system, it is generally to do forward compatibility, otherwise there will be a tragedy like WP6-WP7-WP8. So Apple was very cautious about getting rid of a method, and finally left it behind, leaving a window in its mighty walls for development.
iOS code Modify volume