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?