Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how does one check if UIWebView is empty or not

I need to check if a webview when completed loading has any content or not.

What I require is simple. Its a small webview strip at the bottom of my pages (like an advert)

I call

NSURLRequest *request=[NSURLRequest requestWithURL:adURL];
[gWebView loadRequest:request];

I get the callback

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

But in my scenario the webview shall return empty and sometime it shall have data.

I do not want to show the webview if my server php file returned nothing.

How can I verify that I received an empty page in the callback (or any other way)?

like image 586
Anand Avatar asked Sep 28 '11 10:09

Anand


People also ask

What is the difference between UIWebView and WKWebView?

Difference Between UIWebview and WKWebView UIWebview is a part of UIKit, so it is available to your apps as standard. You don't need to import anything, it will we there by default. But WKWebView is run in a separate process to your app,. You need to import Webkit to use WKWebView in your app.

How can I clear the contents of a UIWebView WKWebView?

To clear old contents of webview With UIWebView you would use UIWebViewDelegate 's - webViewDidFinishLoad: .


1 Answers

If you are loading a HTML page:

NSString *string = [myWebView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('html')[0].innerHTML"];
BOOL isEmpty = string==nil || [string length]==0;

Or you could load the content first, test if it is not empty, and then feed it to the webview. See UIWebView's loadHTMLString:baseURL: or loadData:MIMEType:textEncodingName:baseURL:.

like image 180
Jano Avatar answered Nov 09 '22 23:11

Jano