views:

59

answers:

1

Hi

I understand that applicationWillTerminate is no longer called in iOS4, practically. But I have this situation:

  • my audiobook goes in background mode and keeps playing audio;
  • until version 3.x of SDK I saved the point where one listened to the MP3 file, in applicationWillTerminate;
  • now I was told to keep this saving in applicationWillTerminate (for iPhone 3G) and to implement the same method in applicationDidEnterBackground: but this saves NOT the point where user was at the end, just the point when he entered the background...

But, which is the moment, or better the invoked method, where user exits the application from the application dock? Does this exist?

ApplicationWillTerminate is called when there is a memory problem, but really I can't figure what happens when the user himself shuts down the app.

I repeat: applicationDidEnterBackground does not help me because when the user enters in background mode, he can stays in this position for a long time listening to the audiobook and when he starts again the app, after this is shut down, I mean, he will find the position of the audio file when he entered the background mode…

I'm really confused…

Thanks for your help!

+1  A: 

You should save the play location automatically in applicationWillResignActive:, applicationDidEnterBackground: regardless of whether the audio keeps playing or not. Then put another save in applicationWillTerminate. That way the last play location is saved regardless of what happens next. The next event simply overwrites the saved play location to update it.

An even better option would be to have the audio player object itself trigger the save whenever it is interrupted e.g [AVAudioPlayerDelegate audioPlayerBeginInterruption:] or similar. It might takes some extra work but it would guarantee that the play location was always saved regardless of the cause of the interruption.

TechZen
Using the interruption of the audio player seems like a very good idea to catch this. +1, great answer!
bddckr