【发布时间】:2013-01-14 06:33:50
【问题描述】:
【问题讨论】:
标签: ios objective-c cocoa-touch
【问题讨论】:
标签: ios objective-c cocoa-touch
您可以在应用程序中检测音量按钮按下,但它使用 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];
【讨论】:
看看http://fredandrandall.com/blog/2011/11/18/taking-control-of-the-volume-buttons-on-ios-like-camera/
基本上,您必须初始化音频会话,使其处于活动状态,然后监听更改。最后你发起一个回调。
但是,请谨慎执行硬件命令。无意的滥用可能会导致您被应用商店禁止。
【讨论】: