UIWebView, Oh How I Hate You, Let Me Count The Ways

I've been working on an iOS application that allows the transfer of documents to a secure location for my company.  One of the use cases involves being able to preview the document in a UIWebView.  A user can open these document from another application into this one, which involves me receiving the document.  I take that and make a copy, changing its name to a universally unique name with my own custom file extension.  When I got the code written for previewing it, I always got this error from UIWebView:

Error Domain=WebKitErrorDomain Code=102 UserInfo=0x145bc10 "Frame load interrupted"

This error was very puzzling to me and I spent quite a bit of time trying to diagnose what the problem was.  I went to the simulator file system and tracked down where the file was and validated that the file was not corrupt.  I could load it in Preview just fine and the Internet wasn't really telling me much about this very descriptive error.

I was about to post my own question on StackOverflow when I found this neat little gem.  While I didn't have the exact issue here, it turns out that UIWebView gets confused on the file type if you change it to something it doesn't recognize.  Moral of the story: don't change the extension on a file if you need to load it in UIWebView.

UIWebView, Oh How I Hate You, Let Me Count The Ways.

Posted on Jul 29
Written by Wayne Hartman