1

I have a published (Cocos2d+UIKit)app in the store, which reproduces audio tracks and needs to keep playing them even if the iPhone is locked or the app is in background.

It used to work perfectly well until iOS 5.0 but since iOS 5.1 the app is restarted: sound stops, when user unlocks iPhone doesn't appear active, when opening again it shows the splash screen and initial window.

I tried to debug it but when I lock the iPhone, xCode gets paused in EAGL... I also tried to play the tracks in a MPMoviePlayerViewController and it does the same.

Please help, I am getting many bad reviews every day due to this issue...

2

2 Answers 2

1

It is hard to tell without seeing your code, but as a wild guess, try this line:

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

Put in your first controller's viewDidLoad method. Let me know if it fixes the problem for you.

------ Update -----

An additional thing to check for 5.1 is to set

[[AVAudioSession sharedInstance] setActive: YES error: nil];

before each AVAudioPlayer play command.

This solved it for my alarm clock app which used to sound at the alarm time perfectly in 4.x and started to get muted in 5.1. I found that the putting the above line before [AVAudioPlayer play] solved the problem for me.

2
  • Nothing changed, but thanks for your help. I don't know what code should I write as I don't know where the problem comes from
    – k20
    Mar 17, 2012 at 17:15
  • Thanks again, I was doing that but it did nothing... :(
    – k20
    Mar 17, 2012 at 21:16
1

Think I finally solved it by adding:

 - (void)applicationDidEnterBackground:(UIApplication *)application
{
    [[CCDirector sharedDirector] stopAnimation];
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    [[CCDirector sharedDirector] startAnimation];
      [Appirater appEnteredForeground:YES];
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    [[CCDirector sharedDirector] pause];
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    [[CCDirector sharedDirector] resume];
}

I am not sure why it was working fine before iOS 5.1, but that fixed it :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.