开发者

how to save current state of application

I am making an开发者_StackOverflow iphone application in which after login we will go through some steps and then finally we make a call from within the app. As we know on making call our app quits so plz suggest me how to resume that state on relaunching the app?

1-login

2-some steps

3-list of numbers

4-call

Any help will be appreciated. Thanx..


Saving

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];

// saving an NSString

[prefs setObject:@"TextToSave" forKey:@"keyToLookupString"];

// saving an NSInteger

[prefs setInteger:42 forKey:@"integerKey"];

// saving a Double

[prefs setDouble:3.1415 forKey:@"doubleKey"];

// saving a Float

[prefs setFloat:1.2345678 forKey:@"floatKey"];

[prefs synchronize];

Retrieving

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];

// getting an NSString

NSString *myString = [prefs stringForKey:@"keyToLookupString"];

// getting an NSInteger

NSInteger myInt = [prefs integerForKey:@"integerKey"];

// getting an Float

float myFloat = [prefs floatForKey:@"floatKey"];


Apple has released a document with very clear guidelines as to how you are supposed to handle saving state in iphone applications. All iphone applications are supposed to be robust enough to handle interruption from incoming phone calls or other events at any time and save their state in order to exit gracefully and allow users to resume at a later time.

You will have to write some values to disk (login information, current page, pagestate, etc.) when your application receives the close event from the system.

Then any time you start your application the first thing you will do is check for the existence of a file with those settings in it.

Have you read the iphone application design guidelines or any documentation on the iphone SDK? This topic is covered thorougly in any of the available iphone SDK programming books.


In general, NSUserDefaults is very useful for this sort of thing--as a very basic example, you could save an int which records the state of the application on quit.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜