I would like to bring up the Camera in my app, and let the user take a photo by pressing the hardware volume buttons on the phone.
Is this possible? Can I trigger a function when the users changes the volume, and can I then programatically trigger the camera in this function?
A link or code snippet would be much appreciated.
I second the comments by Frank Krueger and wkw. From a user experience point of view, this sounds like a very bad idea. If you want to try it anyway, you could try this:
The system will now generate a
MPMusicPlayerControllerVolumeDidChangeNotificationwhenever the volume changes. You can register yourself as an observer for the notification with-[NSNotificationCenter addObserver:selector:name:object:]. This is not directly tied to the volume control buttons, though. For instance, it’s also possible that the user inserted or removed headphones and the OS adjusted the volume according to the last setting for this configuration).Also, I believe the volume notification is only for changes of the music volume and not the system/ringer volume. So it would only be posted when music is playing. But I am not certain about this.