Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The EPUB format brings together a bunch of different specifications / formats:</p> <ul> <li>one to say what the content of the book should look like (a subset of XHTML 1.1 + CSS)</li> <li>one to define a "manifest" that lists all of the files that make up that content (OPF, which is an XML file)</li> <li>one to define how everything is packaged up (OEBPS: a zip file of everything in the manifest plus a few extra files)</li> </ul> <p>The specs look a bit daunting but actually once you've got the basics (unzipping, parsing XML) down it's not particularly difficult or complex.</p> <p>You'll need to work out how to download the EPUB, to unzip it somewhere, to parse the manifest and then to display the relevant content. </p> <p>Some pointers if you're just starting out:</p> <ul> <li><a href="http://www.tbxml.co.uk/" rel="noreferrer">parse xml</a></li> <li><a href="http://code.google.com/p/ziparchive/" rel="noreferrer">unzip</a></li> </ul> <p>To display content just use a <code>UIWebView</code> for now.</p> <p>Here's a high level step by step for your code:</p> <p>1) create a view with a <code>UIWebView</code></p> <p>2) download the EPUB file</p> <p>3) unzip it to a subdirectory in your app's documents folder using the zip library, linked above</p> <p>4) parse the XML file at <code>META-INF/container.xml</code> (if this file doesn't exist the EPUB is invalid) using TBXML, linked above</p> <p>5) In this XML, find the first "rootfile" with media-type <code>application/oebps-package+xml</code>. This is the OPF file for the book.</p> <p>6) parse the OPF file (also XML)</p> <p>7) now you need to know what the first chapter of the book is. </p> <p>a) each <code>&lt;item&gt;</code> in the <code>&lt;manifest&gt;</code> element has an id and an href. Store these in an <code>NSDictionary</code> where the key is the id and the object is the href.</p> <p>b) Look at the first <code>&lt;itemref&gt;</code> in the <code>&lt;spine&gt;</code>. It has an idref attribute which corresponds to one of the ids in (a). Look up that id in the <code>NSDictionary</code> and you'll get an href.</p> <p>c) this is the the file of the first chapter to show the user. Work out what the full path is (hint: it's wherever you unzipped the zip file to in (3) plus the base directory of the OPF file in (6))</p> <p>8) create an <code>NSURL</code> using <code>fileURLWithPath:</code>, where the path is the full path from (7c). Load this request using the <code>UIWebView</code> you created in (1).</p> <p>You'll need to implement forward / backward buttons or swipes or something so that users can move from one chapter to another. Use the <code>&lt;spine&gt;</code> to work out which file to show next - the <code>&lt;itemrefs&gt;</code> in the XML are in the order they should appear to the reader.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload