Skip to Main Content
iPhone SDK Programming: Developing Mobile Applications for Apple iPhone and iPod touch
book

iPhone SDK Programming: Developing Mobile Applications for Apple iPhone and iPod touch

by Maher Ali
March 2009
Beginner to intermediate content levelBeginner to intermediate
396 pages
8h 44m
English
Wiley
Content preview from iPhone SDK Programming: Developing Mobile Applications for Apple iPhone and iPod touch

Appendix A. Saving and Restoring App State

Since at most one application can run at a given time, your application should give the user the illusion of being active all the time even if the user hit the Home button. To achieve that, your application should save its current state (e.g., which level of hierarchy it is currently displaying, the current search term, etc.) when the application is terminated, and restore that state when it is relaunched.

There are several ways in which you can maintain this state information. You can, for example, use the SQLite database or flat-files. A property list, however, is ideal for this situation and is the subject of this appendix.

To use property lists for capturing/restoring the state of an application, you need to follow the following guidelines:

  • Represent the state in a dictionary or in an array.

  • The state elements can be instances of NSDictionary, NSArray, NSData, NSDate, NSNumber, and NSString.

  • Add the state elements to the dictionary or the array.

  • Serialize the dictionary or the array into an NSData object using the NSPropertyList-Serialization class method.

  • The NSData object represents the state information in either an XML or a binary format. For efficiency, use binary format.

  • Write the NSData object into a local file in the Documents directory.

  • To restore the state, load the written file into an NSData object and use the NSPropertyListSerialization class method to obtain the dictionary or the array.

In the following, we give an example of saving/restoring ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Microsoft® Office Access 2007 on Demand

Microsoft® Office Access 2007 on Demand

Steve Johnson - Perspection, Inc.
FileMaker Pro 14: The Missing Manual

FileMaker Pro 14: The Missing Manual

Stuart Gripman, Susan Prosser
Microsoft® Office Access™ 2007 Step by Step

Microsoft® Office Access™ 2007 Step by Step

Steve Lambert Joan Lambert and M. Dow Lambert III

Publisher Resources

ISBN: 9780470742822Purchase book