Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIWebView loading and general performance

I am using UIWebView to display textual content in my app (I store the content in local HTML files that I pack with the app). All together, I have three web views whose content I change dynamically based on user feedback.

Although some might argue that this is not the most accepted way, I find UIWebView very convenient to display formatted text, and modify that text using HTML if necessary. While this works 99% of the time, on occasion, I experience problems that generally fall into one of these categories:

  1. Sometimes, the web view content loads slow and is late a second or so.
  2. The content loads but is not showing. However, as long as, I touch the view (try to scroll or something) the content pops in.
  3. A few times I received memory warnings (usually not long after the app's initial loading) that in no way affected the performance of my app. It logged the memory warning but the app worked like nothing happened.

This is the method I use to load content to my web views:

- (void)loadSimpleDocument:(NSString*)documentName inView:(UIWebView*)webView
{
NSString *path = [[NSBundle mainBundle] pathForResource:documentName ofType:@"html"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
}

Aside from this, the shouldStartLoadWithRequest delegate method is also implemented, always returning a YES.

My question is: Is there a way to improve the reliability/performance of my web views (in particular loading)? Is there something I have overlooked, did wrong, or do not know about?

Some additional info: I am on iOS6 SDK, use ARC, and do everything programmatically (do not use IB or storyboard).

like image 712
user1799795 Avatar asked Nov 13 '22 06:11

user1799795


1 Answers

You have 2 options to check what's going on:

  • Implement webViewDidStartLoad & webViewDidFinishLoad delegate methods to check why the content isn't showing (may be the content isn't loaded yet).

  • read the html content to an NSString then use loadHTMLString:baseURL instead of using loadRequest and check if it loads faster.

Hope this could help.

like image 138
MuhammadBassio Avatar answered Nov 15 '22 04:11

MuhammadBassio