Hi, my app need to capture multiple photos with a volume up/down button. To get volume up and down notification while capturing multiple photos. I have use UIApplicationVolumeUpButtonDownNotification. Do apple allow us to use this API?
Can I use api `UIApplicationVolumeUpButtonDownNotification` for getting volume up/down button?
I cannot see this notification in the documentation. Does it mean it is private ?
some discussion here: UIApplicationVolumeUpButtonDownNotification
Review guidelines state that you are not authorised to change the behaviour of hardware buttons:
2.5.9 Apps that alter or disable the functions of standard switches, such as the Volume Up/Down and Ring/Silent switches, or other native user interface elements or behaviors will be rejected.
Depending on how you want to use the Volume Up/Down button, you may infringe this rule and get your app rejected. If you do so in your app however, I would recommend you, on submitting app for review, to explain carefully in the comments to reviewer why you consider you don't infringe guideline 2.5.9.
AVAudioSession has a property "outputVolume".
You could look for changes to this, using Key-value observing...
...and use that to trigger your photo.
That might go against rule 2.5.9, but since Apple's Camera app uses the volume buttons, I think it should be okay.
(Note: this technique does not work in the Simulator, it needs a real device)
Perhaps something like this:
import AVFAudio
class VolumeButtonObserver {
let audioSession = AVAudioSession.sharedInstance()
var outputVolumeObservation: NSKeyValueObservation?
init() {
observeVolumeButtons()
}
func observeVolumeButtons() {
do {
try audioSession.setActive(true)
} catch {}
outputVolumeObservation = audioSession.observe(\.outputVolume) { (audioSession, changes) in
print("A volume button was pressed")
/// Take action here...
}
}
}