-
Notifications
You must be signed in to change notification settings - Fork 0
Data Storage
This page is a work in progress.
In order to meet the varying requirements of the MTM iPhone application and still keep a simple codebase, the iPhone app stores a variety of data on the device using multiple mechanisms. Each storage method has its own advantages, drawbacks, and appropriate use cases.
The iPhone keychain is an extension of Keychain Services for Mac OS X, the "parent" operating system of iOS. It provides a way to store data securely on-disk without fear of tampering or recovery by unauthorized parties. However, keeping data in the keychain requires that the data conform to Apple's secure item model; furthermore, the programmatic keychain interface is less intuitive than other parts of the iPhone app, as it must be written in C. (The MTM iPhone app provides an Objective-C wrapper to these functions, but the implementation is still primarily in C.)
As such, the iPhone app seeks to store only the most secure data in the keychain - other data will be saved using a different mechanism. Data that is stored in the keychain includes:
- Authentication usernames and passwords
- Remote service URLs (e.g. locations of the MTM server application)
The keychain data storage mechanism has a very specific set of properties that it may store for any given data object. As such, we need to find a mapping between Apple's allowed properties and the conceptual items that we must store.
We begin with the concept of a "service account," which encapsulates a URL (for locating a MTM server), a username, and a password. These can be represented easily in memory; now all that's left is to map these items, as well as any auxiliary data for the account, into the keychain. The team settled on the following mapping:
-
kSecAttrLabel: A user-provided name for a service account -
kSecAttrProtocol: The protocol (URL scheme) of the MTM server for the account -
kSecAttrServer: The hostname of the MTM server for the account -
kSecAttrPath: The path portion of the MTM server URL for the account -
kSecAttrComment: An internal identifier label for the account -
kSecAttrAccount: The username for the account -
kSecValueData: The password for the account
A "plist," short for "property list," is a serialized XML file that resides on disk on the device, and can be used for storage of a number of standard data structures. Plists are noted in the Apple development community for their ease of use in storing and retrieving a wide variety of data, most notably settings for an application.
The iPhone MTM app uses plists in precisely this manner: to store a variety of settings, most of which are determined by the user and are not sensitive or cryptographically secure. As an XML file, the plist can store nested structures of data, including arrays and dictionaries. However, at this time there are only a few settings in a flat structure at the root of the plist:
-
IsFirstRun: Whether or not this launch of the application is the first time the app has been run. -
ActiveServiceAccountUUID: The universally unique identifier of the active service account. (For more information about service accounts, see the documentation on the ServiceAccountManager class.)
The standard values of these settings can be seen directly in the Settings.plist file.
Core Data is the leading entity-relationship framework available for the iOS platform, and is also a technology inherited from Mac OS X. Using SQLite as a backing data store, Core Data makes it easy for developers to manage large collections of data with complex relationships between them.
At present, Core Data is not in use within the iPhone MTM application, but is planned for use in the caching framework currently under architecture development.