Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect volume button press and release iOS [duplicate]

Possible Duplicate:
program access to iPhone volume buttons

Is it possible to detect a volume up button press/release in an iOS app?

like image 800
thisiscrazy4 Avatar asked Jan 14 '13 06:01

thisiscrazy4


2 Answers

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];
like image 140
V-Xtreme Avatar answered Sep 30 '22 20:09

V-Xtreme


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.

like image 31
The Obscure Question Avatar answered Sep 30 '22 20:09

The Obscure Question