0

Possible Duplicate:
IOS3 Compatible App in IOS4 Mutlitasking

I have made a quiz application and I need to save the state (timer, an array of question ids, an array containing dictionary objects which says something about what the user has answered and the current index) when the user either press home button or in case of a phone call etc.

However the application will be running at iOS versions < 4.0, so in some cases the multitasking won't be possible.

I have written this, but I can't get notifications for this UIApplicationWillResignActive on iOS 3.1.3 (actual device), on iOS >= 4.0 it works. and I also commented out the UIApplicationWillEnterBackground notification because the app crashes when it is run on a iOS 3.1.3 device, because the notification name isn't available. How can I check if it is available like I do with methods?

    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
    [nc addObserver:self selector:@selector(saveState) name:UIApplicationWillResignActiveNotification object:nil];
    //[nc addObserver:self selector:@selector(loadState) name:UIApplicationWillEnterForegroundNotification object:nil];

Which notification names should I register for and how do save/load state on iOS systems without multitasking and those with?

Thank you.

Community
  • 1
  • 1
LuckyLuke
  • 47,771
  • 85
  • 270
  • 434

3 Answers3

2

Use the isMultitaskingSupported property to determine if you can rely on that method, and change when you save data accordingly. Don't depend on OS version, as even on iOS 4+ it's possible for multitasking to be disabled (rare, yes, but possible)

RyanR
  • 7,728
  • 1
  • 25
  • 39
0

It's generally advisable to save this stuff as you go along. Otherwise you might take too long writing it when your app is quitting.

amergin
  • 3,106
  • 32
  • 44
0

For iOS versions that do not support multi-tasking, you can save state in applicationWillTerminate:. But you don't have a lot of time there to do a lot of work, so you might end up with a partial save. Best to save anything substantial as you go, as @amergin said.

Mark Granoff
  • 16,878
  • 2
  • 59
  • 61