UIWebView没有完成加载? [英] UIWebView not finishing loading?

查看:76
本文介绍了UIWebView没有完成加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中有一个webview。它加载了大部分页面,加载完成后会调用webViewDidFinishLoad函数。但是,虽然页面似乎已加载,但部分页面加载仍未完成。在这些情况下既不是 - (void)webViewDidFinishLoad:(UIWebView *)webView 也不是(void)webView:(UIWebView *)webView didFailLoadWithError 被调用。例如:访问网站 http://www.mynevadacounty.com/ ,当您点击任何一个移动页面加载的项目没有在UIWebView中完成。

I have a webview in my application.It loads most of the pages and the function webViewDidFinishLoad gets called when the loading finishes.But some of the pages loading doesn't finish although the pages appears to be loaded. In these cases neither - (void)webViewDidFinishLoad:(UIWebView *)webView nor (void)webView:(UIWebView *)webView didFailLoadWithError is getting called. For eg: Go to the site http://www.mynevadacounty.com/ and when you click on any of the items such as mobile the page loading doesn't finish in the UIWebView.

可能的原因是什么?

编辑:我试图加载的大多数网站都是sharepoint网站

Most of these sites that i am trying to load are sharepoint sites

推荐答案

我最初做过Q& ;这里有一个异常现象: UIWebView显示UIActivityIndi​​cator用于加载但是在页面最初加载后忽略其他加载请求(例如加载javascript的广告)

I originally did a Q&A of this anomaly here: UIWebView show UIActivityIndicator for loading but ignore additional load requests (e.g. javascript loaded advertisements) after page initially loads

问题是网页将完成加载然后开始加载其他元素之后(即广告,iFrame等)
解决方案是在页面加载开始时存储当前URL和n如果网址与上次加载的URL相同,那么它是正在加载,而不是误报...

The problem is that the webpage will finish loading and then it begins loading other elements afterwards (i.e. advertisements, iFrames, etc.) The solution is to store the current URL when page loading begins and the next time it is "Loading" if the url is the same as the last URL loaded than it's a false positive...

(在网页下面的代码中真实开始加载 // show UIActivityIndi​​cator 并真正完成加载 //隐藏UIActivityIndi​​cator //隐藏UIActivityIndi​​cator的主要内容(不是你正在努力的额外内容)

(In the code below the web page truly starts loading on //show UIActivityIndicator and truly finishes loading the main content (not the extra content you are struggling with) on //hide UIActivityIndicator)

//Define the NSStrings "lastURL" & "currentURL" in the .h file.
//Define the int "falsepositive" in the .h file. (You could use booleans if you want)
//Define your UIWebView's delegate (either in the xib file or in your code)

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    lastURL = [[NSString alloc] initWithFormat:@"%@", webView.request.mainDocumentURL];
    if (falsepositive != 1) {
        NSLog(@"Loaded");
        //hide UIActivityIndicator
    } else {
        NSLog(@"Extra content junk (i.e. advertisements) that the page loaded with javascript has finished loading");
        //This method may be a good way to prevent ads from loading hehe, but we won't do that
    }
}

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType; {
    NSURL *requestURL =[request mainDocumentURL];
    currentURL = [[NSString alloc] initWithFormat:@"%@", requestURL]; //not sure if "%@" should be used for an NSURL but it worked...
    return YES;
}

- (void)webViewDidStartLoad:(UIWebView *)webView {
    if ([currentURL isEqualToString:lastURL]) {
        falsepositive = 1;
        NSLog(@"The page is loading extra content with javascript or something, ignore this");
    } else {
        falsepositive = 0;
        NSLog(@"Loading");
        //show UIActiviyIndicator
    }
}

这篇关于UIWebView没有完成加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆