Very simple to call
First introduced mediaplayer.framework in engineering
#import <MediaPlayer/MediaPlayer.h>
1. Get the System volume
Get System Volume
Mpvolumeview *volumeview = [[Mpvolumeview alloc] init];
UISlider *volumeviewslider= Nil;
For (UIView *view in [Volumeview Subviews]) {
if ([View.class.description isequaltostring:@ "Mpvolumeslider"]) {
Volumeviewslider = (uislider*) view;
Break
}
}
float systemvolume = Volumeviewslider.value;
2. Monitoring methods
[[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (volumechanged:) name:@ " Avsystemcontroller_systemvolumedidchangenotification "Object:nil";
-(void) volumechanged: (nsnotification *) notification
{
[notification.userinfo[@ "Avsystemcontroller_audiovolumenotificationparameter"] floatvalue];
}
3. Remember to destroy OH
-(void) dealloc
{
[[Nsnotificationcenter Defaultcenter] removeobserver:self name:@ "Avsystemcontroller_ Systemvolumedidchangenotification "Object:nil";
}
IOS setting System volume and listening system volume changes