问题
How can i get iphone's current ringer volume level using AVSystemController
I also tried below code to check volume level
MPVolumeView *slide = [MPVolumeView new];
UISlider *volumeViewSlider;
for (UIView *view in [slide subviews]){
if ([[[view class] description] isEqualToString:@"MPVolumeSlider"]) {
volumeViewSlider = (UISlider *) view;
}
}
float val = [volumeViewSlider value];
But when i print / check val, it returns 1.00
I also tried below code
musicPlayer = [MPMusicPlayerController applicationMusicPlayer];
Nslog(@"%f",musicPlayer.volume);
But it also returns 1.00 event if my phone is silent. I refer below link How to determine the current level of the iPhone ringer? but i could not find solution.
Please help.
回答1:
Try this:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(volumeChanged:)
name:@"AVSystemController_SystemVolumeDidChangeNotification"
object:nil];
- (void)volumeChanged:(NSNotification *)notification{
NSDictionary*dict=notification.userInfo;
float newVolume =
[[dict objectForKey:@"AVSystemController_AudioVolumeNotificationParameter"]floatValue];
//my comment: newVolume is value that you need
}
来源:https://stackoverflow.com/questions/23517085/get-ringer-volume-level-using-avsystemcontroller-in-ios