开发者

How to tell in code if the user has "Locked the Volume" in their settings menu

开发者 https://www.devze.com 2023-03-24 23:50 出处:网络
Currently, I\'m setting the volume to max, and then checking if the volume is at max, or a lower value. If it\'s at a lower value, then the user must have a Volume Lock on their system.

Currently, I'm setting the volume to max, and then checking if the volume is at max, or a lower value. If it's at a lower value, then the user must have a Volume Lock on their system.

This works fine, but I'm wondering if there is some method to call, or property to check which tells me this in code for free? I've been looking online as to how to do this, but I can't seem to find anything. Thanks in advance!

Edit: It turns out that my previous method of setting the max volume and then checking if it's lower to see if there is a Volume lock does not work on the device. It seems as though the volume is sc开发者_开发百科aled with the Volume lock, instead of just being cut off.

Now I'm completely stuck on this. Is there even any private methods or properties that I can use in order to detect this?


I think what you are asking for is to find out if the iphone has a cap on the volume limit. I have looked for the answer but could not find one. Here is a way just to check the volume level, hope this helps.

In your XIB you can add a slider to check what the volume level is at, so basically you can tell if it is silent, and know the level of the volume. For more understanding of this class, here's the link http://blog.stormyprods.com/2008/09/proper-usage-of-mpvolumeview-class.html but try this first:

The following code will create something like a volume bar.

  - (void)viewDidLoad {
            // create a frame for MPVolumeView image
     CGRect frame = volumeViewHolder.bounds; // CGRectMake(0, 5, 180, 0);
     volumeView = [[[MPVolumeView alloc] initWithFrame:frame] autorelease];
     [volumeView sizeToFit];
     [volumeViewHolder addSubview:volumeView];

     for (UIView *view in [volumeView subviews]){
      if ([[[view class] description] isEqualToString:@"MPVolumeSlider"]) {
       volumeViewSlider = view;
      }
     }
     [[NSNotificationCenter defaultCenter] addObserver:self 
          selector:@selector(volumeChanged:) 
          name:@"AVSystemController_SystemVolumeDidChangeNotification" 
          object:nil];
    }
    - (void) volumeChanged:(NSNotification *)notify
    {
    [volumeViewSlider setValue:[[[notify userInfo] objectForKey:@"AVSystemController_AudioVolumeNotificationParameter"] floatValue]];
    }

I heard that for some reason apple doesn't allow you to sell an app if you use a certain class (the one in my example) but I'm not too sure about this, I would double-check and make sure that you are 'allowed' to use it. But the code should work.


There are many answers to this problem but they all seem to have fallen foul of Apple's guidelines or App Store curators at some point as Apple don't provide an official way to do this.

However one feature you can utilise to find this out is that when a device is muted then the OS will not play the sound at all - so if you play a 800ms sound file and you time how long it takes to play if it is less than 800ms then you can infer that the mute switch is on.

I would recommend to use a silent 800ms sound file to use this trick so that the user is not suddenly confronted with an unexpected sound.

See here for the article that inspired me: http://inforceapps.wordpress.com/2009/07/08/detect-mute-switch-state-on-iphone/

In addition you might want to use the Audio Toolbox to do this simply and guarantee that the mute switch is being used.


Consider setting the volume to max, then recording the output channel, and playing a short tone - then compare the peak of that recorded sample to a known sample where the volume limiter is not present. This will work if the iPad scales the output volume before recording gets access to it.

I wish I had more info on how to record the output, but I don't have much personal experience with it. Somebody who is versed in recording input should be able to point you the right way.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号