1

I'm displaying two HTML5 documents on my iPad application, using a UIWebView on iOS 6.0.1.
One of them has no problems and I can open and close the webview as much as I want. The other one can be displayed once and then when I close my web view and want to re-open the document again, the webview shows a black screen.

I haven't prepared the HTML5 documents myself and I don't have much knowledge on HTML5, so I can't tell the difference between them that causes this behavior.

Here's how I create my webview and how I load the HTML5:

UIWebView *theWebView = [[UIWebView alloc] init];

theWebView.scalesPageToFit = YES;
theWebView.clearsContextBeforeDrawing = YES;
theWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);

//adjust frame and add to view controller's view here

NSURL *url = [NSURL URLWithString:@"http://www.handypdf.net/davsan"];
[theWebView loadRequest:[NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60.0]];

Everytime I open an HTML5 document, I re-create the web view. So I don't re-use it.

To fix the problem, I tried cleaning the cache, cookies, etc.. explained on these SO answers, but it didn't work.

Here are the links to the problematic and the not-problematic HTML documents:

This one works ok. This one doesn't work the second time.

Also, if you want to check these HTML5 pages online here are the links to them:

This one works ok. This one doesn't work the second time.

This problem does not happen on iOS 5.x. It's also replicable using the iOS simulator. What would you suggest to fix it?

Thx

Community
  • 1
  • 1
aslı
  • 8,740
  • 10
  • 59
  • 80

1 Answers1

0

Not a satisfying answer, but here's how I progressed with this problem:

I couldn't solve this for a couple of days. Then I deleted all my code and re-wrote the functionality from scratch, and then it was solved. I couldn't understand the exact reason, because I didn't write anything fancy on my second attempt, so unfortunately I can't tell how it's solved :(

Here is what I just did:

Create the web view once, and cache it:

+(UIWebView *)getTheWebView {
    if (theWebView) return theWebView;

    theWebView = [[UIWebView alloc] init];
    theWebView.scalesPageToFit = YES;
    theWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
    return theWebView;
} 

Then, when I want to show the web view:

UIWebView *theWebView = [HTML5Manager getTheWebView];
theWebView.frame = self.view.frame;

[self.view addSubview:theWebView];

And here's how I load the URL:

[theWebView loadRequest:[NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60.0]];

This is just it and it works. I know it doesn't make sense but I hope it helps you, too...

aslı
  • 8,740
  • 10
  • 59
  • 80