ios SimpleAudioEngine setMode kAMM_MediaPlayback

Hello, i have some problem, plz someone help me

first my development env :

  • cocos2d-x version 2.0.4
  • iphone4 device (ios6.0.1)

i want to use SimpleAudioEngine~~>CDAudioManager customize,
because i want to play music audioSessionCategory = AVAudioSessionCategoryPlayback
i have changed some code…
in CDAudioManager.m
// Init

  • sharedManager
    {
    @synchronized {
    if {
    if {
    //Set defaults here
    //configuredMode = kAMM_FxPlusMusicIfNoOtherAudio;
    configuredMode = kAMM_MediaPlayback; // I want to set audioSessionCategory
    }
    sharedManager = init:configuredMode];
    _sharedManagerState = kAMStateInitialised;//This is only really relevant when using asynchronous initialisation
    postNotificationName:kCDN_AudioManagerInitialised object:nil];
    }
    }
    return sharedManager;
    }

if i changed that code,
it work on foreground&background is good
but, foreground inactive state few second later turn on screen, then my app is crash!
I’m going to crazy please help me
Background Mode good work, but foreground inactive mode~~> few second( audio is good work ) ~~> active mode crash
Error code & stack
libGPUSupportMercury.dylib`gpus_ReturnNotPermittedKillClient:
CCEGLView::swapBuffers
CCDirector::drawScene
CCDisplayLinkDirector::mainLoop

P.S.
I set to Required background mode~~ app plays audio

it wat not problem : stopAnimation, startAnimation,
background is good work,

I Fixed it!

but, I don’t know what problem, just no crash~!

UIApplicationState has 3 types
UIApplicationStateActive - Foreground
UIApplicationStateInactive - Power button
UIApplicationStateBackground - Home button

then, if UIApplication was called ‘applicationWillEnterForeground’
check the UIApplicationState,
if it was UIApplicationStateInactive, call performSelector

follow AppController.mm

  • (void)applicationWillEnterForeground:(UIApplication )application {
    /

    Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
    */

if( [UIApplication sharedApplication].applicationState == UIApplicationStateInactive ) {
[self performSelector:@selector(CallCocosEnterForeground) withObject:nil afterDelay:.1f];
}else {
[self CallCocosEnterForeground];
}
}

  • (void)CallCocosEnterForeground {
    cocos2d::CCApplication::sharedApplication()->applicationWillEnterForeground();
    }