Possible Duplicate:
program access to iPhone volume buttons
Is it possible to detect a volume up button press/release in an iOS app?
You can detect the volume button press in your application, but it uses a private API of Apple. Since they don't allow you to use their private APIs in your application, this leads straight away to the rejection your application, so use this at your own risk.
In your viewDidLoad:
, for example:
MPVolumeView *volumeView = [[MPVolumeView alloc] initWithFrame:CGRectMake(18, 340, 284, 23)];
[self.view addSubview:volumeView];
[NSNotificationCenter.defaultCenter
addObserver:self
selector:@selector(volumeDidChange:)
name:@"AVSystemController_SystemVolumeDidChangeNotification"
object:nil];
Take a look at http://fredandrandall.com/blog/2011/11/18/taking-control-of-the-volume-buttons-on-ios-like-camera/
Essentially you have to initialize an audio session, make it active, and then listen for changes. Finally you initiate a callback.
However, be careful with your implementations of hardware commands. Unintentional misuse can get you banned from the app store.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With