3

I'm developing an app with some camera functionality and I'd like to use the volume buttons to take a picture (as the Apple Camera app does).

Using MPVolumeView and this snippet:

let rect = CGRect(x: -500, y: -500, width: 0, height: 0)
let volumeView = MPVolumeView(frame: rect)
UIApplication.sharedApplication().windows.first?.addSubview(volumeView)

and registering to AVSystemController_SystemVolumeDidChangeNotification notifications I'm able to intercept when the button is pressed and avoid showing the volume HUD.

This trick works unless the setting "Change with Buttons" in Settings > Sounds is on. In that case, I still get the notification, but the HUD will appear.

Any idea how to hide the HUD even when that setting is on?

Luca Torella
  • 7,974
  • 4
  • 38
  • 48

1 Answers1

0

I know for sure that the JPSVolumeButtonHandler available on GitHub can

Hide the HUD typically displayed on volume button presses.

I found that the workaround solution is here but it's similar to your solution:

- (void)disableVolumeHUD 
{
    self.volumeView = [[MPVolumeView alloc] initWithFrame:CGRectMake(MAXFLOAT, MAXFLOAT, 0, 0)];
    [[[[UIApplication sharedApplication] windows] firstObject] addSubview:self.volumeView];
}

I suggest to look at this repository, it's works very well and I suppose reading the description also when

the setting "Change with Buttons" in Settings > Sounds is on

Massimo Polimeni
  • 4,826
  • 4
  • 27
  • 54