Question

I'm testing a UIWebview with a number of different document types - .xlsx, .jpg, etc. - and it opens most of them just fine. From time to time, I open a local file and this message appears right in the web view:

Unable to Read Document
An error occurred while reading the document

I'm not concerned with "why" this error occurs - it happens, for instance, when I feed the UIWebView a garbage file (intentionally). The problem is that I can't figure out how to detect "when" this happens. It doesn't trigger webView:didFailLoadWithError, it doesn't trigger an NSException (via @try & @catch), and when I inspect the document in webViewDidFinishLoad, webView.request.HTTPBody is null.

Anyone know how to detect when UIWebView can't display content?

Was it helpful?

Solution

just call uiwebview delegate method 

- (void)webViewDidStartLoad:(UIWebView *)webView
{

}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    NSString *html = [webView stringByEvaluatingJavaScriptFromString:
                      @"document.body.innerHTML"];
    if ([html rangeOfString:@"Unable to Read Document."].location == NSNotFound) {

       NSLog(@"NO Error");

    }
    else
    {
//        NSLog(@"File contains Error");
    }

}

OTHER TIPS

If inspecting the log does not show anything out of the ordinary, run it on the actual device. As a bit of help, my log says

Cannot find data converter callback for uti public.data
Failed to generate preview

which means that the simulator is failing. After being frustrated with this same problem, I went thru the whole final certification and installation and provisioning process, and too confirm that Word 97 and Pages / Pages.zip files containing text do indeed display just fine on the actual device. SOLVED. The simulator itself is broken, which is very...troubling, that this little note didn't seem to make it into the release notes, and also complicates development a tad bit. However, the work around is to select the Device in Xcode and deploy out, and it should work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top