Fix iOS 5.1.1 crash caused by interruptionHandler

checks OS version and sets handling based on what is available.
This commit is contained in:
Justin Hawkwood 2015-04-03 15:57:47 -07:00
parent 42cc17621f
commit 84fd73630a
1 changed files with 20 additions and 0 deletions

View File

@ -141,11 +141,31 @@ namespace cocos2d {
@implementation AudioEngineSessionHandler
void AudioEngineInterruptionListenerCallback(void* user_data, UInt32 interruption_state)
{
if (kAudioSessionBeginInterruption == interruption_state)
{
alcMakeContextCurrent(nullptr);
}
else if (kAudioSessionEndInterruption == interruption_state)
{
OSStatus result = AudioSessionSetActive(true);
if (result) NSLog(@"Error setting audio session active! %d\n", result);
alcMakeContextCurrent(s_ALContext);
}
}
-(id) init
{
if (self == [super init])
{
if ([[[UIDevice currentDevice] systemVersion] intValue] > 5) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleInterruption:) name:AVAudioSessionInterruptionNotification object:[AVAudioSession sharedInstance]];
}
else {
AudioSessionInitialize(NULL, NULL, AudioEngineInterruptionListenerCallback, self);
}
}
return self;
}