IPhone SDK: UIWebView for stopping images on upload / download

How can I use UIWebView in Xcode so that it does NOT load images when loading pages (to bring up a faster loading page)?

+5
source share
4 answers

UIWebViewis the pale, white little shadow of WebKit full WebView, which is easy for. -webView:shouldStartLoadWithRequest:navigationType:only called for navigation. It is not called for every request, such as WebPolicyDelegateon mac. C UIWebView, here is how I could attack this problem:

-webView:shouldStartLoadWithRequest:navigationType: NO. NSURLConnection. NSURLConnection , IMG- , . UIWebView -loadHTMLString:baseURL:.

, HTML iPhone, Javascript , , , .

+4

. , loadHTMLString: baseURL: NO, webView: shouldStartLoadWithRequest: navigationType: . ( , loadHTMLString shouldStartLoadWithRequest).

YES/NO NSScanner HTML src= "http://..." src=""

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    if (pageHasNoImages==YES)
    {
        pageHasNoImages=FALSE;
        return YES;     
    }
    NSString* newHtml;
    NSString* oldHtml;
    NSData *urlData;
    NSURLResponse *response;
    NSError *error;
    urlData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    oldHtml=[[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding];

    newHtml=[self.detail scannerReplaceImg:oldHtml]; // my own function to parse HTML
    newHtml=[self.detail scannerReplaceAds:newHtml]; // my own function to parse HTML
    if (newHtml==nil) 
    {
        NSLog(@"newHtml is nil");
        newHtml=oldHtml;
    }
    [oldHtml release];

    pageHasNoImages=TRUE;
    [web loadHTMLString:newHtml baseURL:request.URL];

    return NO;
}
+1

UIWebView, :

webView:shouldStartLoadWithRequest:navigationType:

navigationType . , , NO navigationType == UIWebViewNavigationTypeOther.

0

Does this really cause the page to load faster? it looks like the images are still loading, but we just don't feed them in the UIWebView.

or does shouldStartLoadWithRequest load the HTML text first?

0
source

All Articles