Objective-C: volumeChanged wasn't called even add a Observer for AVSystemController_SystemVolumeDidChangeNotification?
- (void)viewDid开发者_如何学PythonLoad {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(volumeChanged:) name:@"AVSystemController_SystemVolumeDidChangeNotification" object:nil];
}
- (void)volumeChanged:(NSNotification *)notification{
float volume = [[[notification userInfo] objectForKey:@"AVSystemController_AudioVolumeNotificationParameter"] floatValue];
//[self innerSetVolume:volume];
}
volumeChanged will not be called when I push the up/down hardware volume button on device. somebody met the question before?
PS:my test device is iPod touch with iOS 4.3, not iPhone.
I believe you need to start up Audio Session Services in order for those notifications to fire.
Here's the documentation for the call -- http://developer.apple.com/library/ios/documentation/AudioToolbox/Reference/AudioSessionServicesReference/Reference/reference.html#//apple_ref/c/func/AudioSessionSetActive
精彩评论