需要在:didFinishLaunchingWithOptions:(NSDictionary *)launchOptions方法中加入一下监听事件:
<pre name="code" class="objc"> //监听系统音量控制
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(volumeChanged:)
name:@"AVSystemController_SystemVolumeDidChangeNotification"
object:nil];
然后实现对应的通知事件:
- (void)volumeChanged:(NSNotification *)notification
{
float volume =
[[[notification userInfo]
objectForKey:@"AVSystemController_AudioVolumeNotificationParameter"]
floatValue];
NSLog(@"%f", volume);
}