Detect volume button press and release iOS

Possible duplicate:
to access iPhone volume buttons

Can I set the volume up button in an iOS app?

+4
source share
2 answers

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 the audio session, activate it, and then listen to the changes. Finally, you initiate a callback.

However, be careful with your hardware command implementations. Inadvertent misuse may force you to prohibit use of the app store.

+3
source

You can determine if the volume button is pressed in the application, but uses the Apple private API. Since they do not allow the use of their private APIs in your application, this immediately leads to the failure of 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]; 
+4
source

All Articles