5

可能重复:
程序访问 iPhone 音量按钮

是否可以在 iOS 应用程序中检测到音量增大按钮按下/释放?

4

2 回答 2

5

您可以在应用程序中检测音量按钮按下,但它使用 Apple 的私有 API。由于他们不允许您在您的应用程序中使用他们的私有 API,这会直接导致您的应用程序被拒绝,因此使用它需要您自担风险。

在你的viewDidLoad:,例如:

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];
于 2013-01-14T06:46:00.743 回答
3

看看http://fredandrandall.com/blog/2011/11/18/taking-control-of-the-volume-buttons-on-ios-like-camera/

本质上,您必须初始化音频会话,使其处于活动状态,然后监听更改。最后你发起一个回调。

但是,请注意硬件命令的实现。无意的滥用可能会让您被禁止进入应用商店。

于 2013-01-14T06:38:05.790 回答