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)?
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.
To clear old contents of webview With UIWebView you would use UIWebViewDelegate 's - webViewDidFinishLoad: .
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:
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With