views:

255

answers:

3

I have an app that functions much like an ebook. I have a bunch of textual information in various languages that is accessible through a number of drill down methods. When a user wants to get into where they were reading last, they currently have to navigate through the section and chapter menus to get back to where they were. An ideal solution for this would be to setup a bookmark system, which I am considering.

But if I remember correctly, when iPhone OS 4 was announced, they seemed to make a big deal of the added ability to save the state of an app. Does that mean that someone using my reader app would be able to just exit right out, do whatever, and then when they came back in, it would be the reading screen just as they left it?

I don't know much about how to setup a bookmarking system, I suppose it would be worth investigating, but I would probably want to just hold off for iPhone OS 4 if that is indeed what it will be capable of doing. Any thoughts or insights would be appreciated!!

+5  A: 

This has always been possible in the iPhone OS. Most people use NSUserDefaults to store their application's state. Then in your application delegate's -applicationDidFinishLaunching method, or wherever you set up your views and initialize your application state, simply restore the state that you saved using NSUserDefaults.

Jeff Kelley
+3  A: 

What they meant for save state is for background application. A ebook app probably won't need to run in the background so you'll still have to save and restore state just like in OS 3. NSUserDefaults works well for this.

Hua-Ying
+4  A: 

As others have pointed out this is not particular to OS4 and it is good practice to implement this in all apps.

I would suggest that when a user turns a page in a book for example you save a reference to that page using NSUserDefaults as follows:

NSUserDefaults *userPreferences = [NSUserDefaults standardUserDefaults];
[userPreferences setObject:currentPageNumber forKey:@"pageNumber"];

When the application launches you can read this value and act accordingly.

[[NSUserDefaults standardUserDefaults] stringForKey:@"pageNumber"];

You may prefer only to store the reference when the application is about to close but it is better practice to store it earlier (in case the application quits unexpectedly)


Also, you mention that users navigate through a number of "drill down methods". You may want to keep a record in a NSMutableArray of where exactly the user is in the app and save this out to NSUserDefaults too. When your app launches you would process the information in this array to get the user back to where they left off.

prendio2