需要在: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);
}