Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

brendan09

macrumors newbie
Original poster
Nov 10, 2008
13
0
I have searched hours and hours for a solution to prevent UIWebView from downloading images when it renders a page. The webview is hidden, so the user can't see it anyway. This webview queries a server and receives an html page as a result. I have it render the html so that i can inject and run a piece of javascript into the page so that i can extract some information from it. Everything in my code works perfectly with the exception that the code to run the javascript doesn't run until webViewDidFinishLoad is called. This isn't called until after ALL images have been downloaded... this can be excessively slow on the cellular network. The number of images depend upon the query. I don't have access to the code on the server, so i can't stop it from returning images. Any solution or suggestion is appreciated. Thanks!!
 
You might want to consider this approach: instead of loading the HTML into a UIWebView, load it into an NSString object, via the initWithContentsOfURL: method, and then mess with it from there.
 
There is a callback to the webview delegate shouldStartLoadWithRequest:. I haven't used it for this purpose but I think you can return NO for all images if you want and I think it will do what you want.
 
@dejo
-It seems that i should be able to do what i need with this; however, whenever it hits this line:
Code:
 NSString * webContents = [NSString initWithContentsOfURL:URL];
It crashes. The URL is fine, it loads great in a webView.

@PhoneyDeveloper
-I've explored shouldStartLoadWithRequest, it doesn't seem to work for this purpose. It only seems to run this whenever a new page is starting to load. It won't let me check for individual elements that are loading within the page.

-Not sure why it keeps crashing on that line. I've tried several variations from several sources on the web and none of them seem to work, they all crash.
 
It crashes because a) you didn't see the compile warning/error first, and b) initWithContentsOfURL is an instance method, not a class method. If you don't know the difference between those, I'd suggest reading up on Objective-C.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.