Note that there are some explanatory texts on larger screens.

plurals
  1. POiPhone UIWebView: loadData does not work with certain types (Excel, MSWord, PPT, RTF)
    text
    copied!<p>My task is to display the supported document types on an iPhone with OS 3.x, such as .pdf, .rtf, .doc, .ppt, .png, .tiff etc.</p> <p>Now, I have stored these files <strong><em>only encrypted</em></strong> on disk. For security reasons, I want to avoid storing them unencrypted on disk.</p> <p>Hence, I prefer to use <code>loadData:MIMEType:textEncodingName:baseURL:</code> instead of <code>loadRequest:</code> to display the document because <code>loadData</code> allows me to pass the content in a NSData object, i.e. I can decrypt the file in memory and have no need to store it on disk, as it would be required when using <code>loadRequest</code>.</p> <p>The problem is that <code>loadData</code> does not appear to work with all file types:</p> <p>Testing shows that all picture types seem to work fine, as well as PDFs, while the more complex types don't. I get a errors such as:</p> <pre><code>NSURLErrorDomain Code=100 NSURLErrorDomain Code=102 </code></pre> <p>WebView appears to need a truly working URL for accessing the documents as a file, despite me offering all content via the NSData object already.</p> <p>Here's the code I use to display the content:</p> <pre><code>[webView loadData:data MIMEType:type textEncodingName:@"utf-8" baseURL:nil]; </code></pre> <p>The mime-type is properly set, e.g. to "application/msword" for .doc files.</p> <p>Does anyone know how I could get <code>loadData</code> to work with all types that loadRequest supports? Or, alternatively, is there some way I can tell which types do work <em>for sure</em> (i.e. officially sanctioned by Apple) with loadData? Then I can work twofold, creating a temp unencrypted file only for those cases that loadData won't like.</p> <p><strong>Update</strong></p> <p>Looks like I'm not the first one running into this. See here:</p> <p><a href="http://osdir.com/ml/iPhoneSDKDevelopment/2010-03/msg00216.html" rel="noreferrer">http://osdir.com/ml/iPhoneSDKDevelopment/2010-03/msg00216.html</a></p> <p>So, I guess, that's the status quo, and nothing I can do about it.</p> <p>Someone suggested a work-around which might work, though:</p> <p><a href="http://osdir.com/ml/iPhoneSDKDevelopment/2010-03/msg00219.html" rel="noreferrer">http://osdir.com/ml/iPhoneSDKDevelopment/2010-03/msg00219.html</a></p> <p>Basically, the idea is to provide a tiny http server that serves the file (from memory in my case), and then use loadRequest. This is probably a bit more memory-intensive, though, as both the server and the webview will probably both hold the entire contents in memory as two copies then, as opposed to using loadData, where both would rather share the same data object. (Mind you, I'll have to hold the decrypted data in memory, that's the whole point here).</p>
 

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