Reading and Writing Local Files
Until very recently, the idea of JavaScript in a browser having access to the client filesystem in any fashion beyond cookies was blue-sky thinking. Security concerns are genuine issues on the Web, and handing hard disk access to any website you stumble upon (or are misled to visit) is a recipe for disaster and pwnage. But standalone applications have traditionally had access to the mass storage device(s) attached to the client. For example, there are plenty of disk utility software programs for Mac OS X, Windows (all flavors), Unix, and many other operating systems—utilities that have free rein over the most private of files. iOS meets you about halfway.
An important design consideration to bear in mind is that Apple’s user interface design guidelines advise strongly against exposing iOS directory structures of any kind to users. Data storage is just supposed to happen, and that’s all there is to it. For example, Apple’s Notes app presents each document (note) as a page in the app. You can view a list of notes as a kind of table of contents, but they’re not files in the user’s eye. Any “file-ness” of content should be reserved for special interfaces, such as the File Sharing area of the iTunes display (in the Apps tab for the iPad OS 3.2 and iOS 4 or later).
If an iOS app developer follows the rules set down by Apple, access to files is somewhat limited. Each application is given room to read and write files, but only within the directory the OS creates ...
Get Learning the iOS 4 SDK for JavaScript Programmers now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.