<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: URL filtering for UIWebView on the iPhone</title>
	<atom:link href="http://www.icab.de/blog/2009/08/18/url-filtering-with-uiwebview-on-the-iphone/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.icab.de/blog/2009/08/18/url-filtering-with-uiwebview-on-the-iphone/</link>
	<description>iCab related stuff; Mac, iPhone and Cocoa programming</description>
	<lastBuildDate>Fri, 10 Sep 2010 12:44:28 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Alexander</title>
		<link>http://www.icab.de/blog/2009/08/18/url-filtering-with-uiwebview-on-the-iphone/comment-page-1/#comment-3633</link>
		<dc:creator>Alexander</dc:creator>
		<pubDate>Fri, 30 Jul 2010 14:24:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=35#comment-3633</guid>
		<description>@Gabriel
You&#039;re right. But the problem is that you don&#039;t have many choices on iOS. The only way to manipulate the web page that is shown in a UIWebView object is through JavaScript. Apple has removed all other ways to access the content, which you might know from the Mac APIs.

If you need to manipulate the content before it is displayed, you could load the data manually yourself (using the NSURLConnection API) and then feed the result to UIWebView. But this can get extremely complicated, because you have to parse the content yourself to find all the references to external files and you need to load them yourself as well. And after all the files are loaded, filtered and modified according to your needs, you have to combine all the stuff again so that a valid web page with valid references to these external files can be passed to UIWebView. 

Maybe you can hide the UIWebView while loading the web page, manipulate the page after the page load has finished and afterwards show the page to the user. This could be a much easier solution that loading all the stuff yourself, like described above. But in all cases, it&#039;s most likely no longer possible to allow the user to navigate and interact with the page while it is still loading.

My blog post addresses the &quot;normal&quot; filtering, to block ads and similar stuff. Here the URL-based filtering is usually working just fine. If you need to filter the content itself, you have to do much more and this can get messy and complicated.</description>
		<content:encoded><![CDATA[<p>@Gabriel<br />
You&#8217;re right. But the problem is that you don&#8217;t have many choices on iOS. The only way to manipulate the web page that is shown in a UIWebView object is through JavaScript. Apple has removed all other ways to access the content, which you might know from the Mac APIs.</p>
<p>If you need to manipulate the content before it is displayed, you could load the data manually yourself (using the NSURLConnection API) and then feed the result to UIWebView. But this can get extremely complicated, because you have to parse the content yourself to find all the references to external files and you need to load them yourself as well. And after all the files are loaded, filtered and modified according to your needs, you have to combine all the stuff again so that a valid web page with valid references to these external files can be passed to UIWebView. </p>
<p>Maybe you can hide the UIWebView while loading the web page, manipulate the page after the page load has finished and afterwards show the page to the user. This could be a much easier solution that loading all the stuff yourself, like described above. But in all cases, it&#8217;s most likely no longer possible to allow the user to navigate and interact with the page while it is still loading.</p>
<p>My blog post addresses the &#8220;normal&#8221; filtering, to block ads and similar stuff. Here the URL-based filtering is usually working just fine. If you need to filter the content itself, you have to do much more and this can get messy and complicated.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gabriel</title>
		<link>http://www.icab.de/blog/2009/08/18/url-filtering-with-uiwebview-on-the-iphone/comment-page-1/#comment-3630</link>
		<dc:creator>Gabriel</dc:creator>
		<pubDate>Fri, 30 Jul 2010 10:34:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=35#comment-3630</guid>
		<description>@Alexander
I have thought of the JS approach, but here are two remarks (suppose I am writing some Parental-Control Child-Safe Browser app):

1) The JS code that your application can make the UIWebView execute, is run after the page has been completed loaded (ie . after the body onload event), so that you cannot actually prevent other inline onload handlers written in the HTML source, for example.

2) It is quite complex to parse in JS the whole HTML file for specific keywords or phrases in order to finally strip them out or completely blank out the page, whereas it is pretty simple to do so while working on an NSString content, prior to handing it over the UIWebView.

Would you recommend another approach, more low-level than the JS one,
Thanks a lot.</description>
		<content:encoded><![CDATA[<p>@Alexander<br />
I have thought of the JS approach, but here are two remarks (suppose I am writing some Parental-Control Child-Safe Browser app):</p>
<p>1) The JS code that your application can make the UIWebView execute, is run after the page has been completed loaded (ie . after the body onload event), so that you cannot actually prevent other inline onload handlers written in the HTML source, for example.</p>
<p>2) It is quite complex to parse in JS the whole HTML file for specific keywords or phrases in order to finally strip them out or completely blank out the page, whereas it is pretty simple to do so while working on an NSString content, prior to handing it over the UIWebView.</p>
<p>Would you recommend another approach, more low-level than the JS one,<br />
Thanks a lot.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alexander</title>
		<link>http://www.icab.de/blog/2009/08/18/url-filtering-with-uiwebview-on-the-iphone/comment-page-1/#comment-3623</link>
		<dc:creator>Alexander</dc:creator>
		<pubDate>Thu, 29 Jul 2010 22:13:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=35#comment-3623</guid>
		<description>@Gabriel
Filtering the content of a web page is a totally different task. When using UIWebView you can only modify the content after the page is loaded and this can only be done using JavaScript. Using JavaScript you can modify the page content at code level and DOM level. This can be difficult if you need to do this on all web pages that are loaded. In case you do exactly which pages are loaded and have to be modified, you can explicitly target the code structure of this page.</description>
		<content:encoded><![CDATA[<p>@Gabriel<br />
Filtering the content of a web page is a totally different task. When using UIWebView you can only modify the content after the page is loaded and this can only be done using JavaScript. Using JavaScript you can modify the page content at code level and DOM level. This can be difficult if you need to do this on all web pages that are loaded. In case you do exactly which pages are loaded and have to be modified, you can explicitly target the code structure of this page.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gabriel</title>
		<link>http://www.icab.de/blog/2009/08/18/url-filtering-with-uiwebview-on-the-iphone/comment-page-1/#comment-3621</link>
		<dc:creator>Gabriel</dc:creator>
		<pubDate>Thu, 29 Jul 2010 21:32:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=35#comment-3621</guid>
		<description>Hello, thanks for sharing.
What if you must filter the actual contents of the response? not only from rules on the URL? In the code presented in this article, I can&#039;t see how to edit/parse the actual response data.
Thanks.</description>
		<content:encoded><![CDATA[<p>Hello, thanks for sharing.<br />
What if you must filter the actual contents of the response? not only from rules on the URL? In the code presented in this article, I can&#8217;t see how to edit/parse the actual response data.<br />
Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alexander</title>
		<link>http://www.icab.de/blog/2009/08/18/url-filtering-with-uiwebview-on-the-iphone/comment-page-1/#comment-3575</link>
		<dc:creator>Alexander</dc:creator>
		<pubDate>Sat, 24 Jul 2010 13:46:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=35#comment-3575</guid>
		<description>@Michael
In my example I&#039;m just returning an empty &quot;dummy&quot; response instead of an image from within the Cache object. But I think if you would return the data of a real image file (like a 1x1 pixel fully transparent GIF image file), you won&#039;t get these &quot;missing image&quot; icons anymore. 

But please note that in many cases it can be nevertheless a good idea to let UIWebView show the &quot;missing image&quot; icons. This shows the user that some objects are not loaded. So if the users misses some important information, the &quot;missing image&quot; icons can help to show the user that a filter might be responsible for this and switching off the filters might solve the issue. If there&#039;s no indication at all that something is missing, the user might be confused.</description>
		<content:encoded><![CDATA[<p>@Michael<br />
In my example I&#8217;m just returning an empty &#8220;dummy&#8221; response instead of an image from within the Cache object. But I think if you would return the data of a real image file (like a 1&#215;1 pixel fully transparent GIF image file), you won&#8217;t get these &#8220;missing image&#8221; icons anymore. </p>
<p>But please note that in many cases it can be nevertheless a good idea to let UIWebView show the &#8220;missing image&#8221; icons. This shows the user that some objects are not loaded. So if the users misses some important information, the &#8220;missing image&#8221; icons can help to show the user that a filter might be responsible for this and switching off the filters might solve the issue. If there&#8217;s no indication at all that something is missing, the user might be confused.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael</title>
		<link>http://www.icab.de/blog/2009/08/18/url-filtering-with-uiwebview-on-the-iphone/comment-page-1/#comment-3570</link>
		<dc:creator>Michael</dc:creator>
		<pubDate>Sat, 24 Jul 2010 04:00:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=35#comment-3570</guid>
		<description>Hey, great blog post, maybe only one of its kind on the Internet...?

Anyways, I&#039;ve managed to block images from loading in my UIWebView, but in their place I have those ugly little blue squares with a question mark.

Any suggestions on how to just get a blank square instead of the little blue placeholder?

Thanks in advance (BTW I bought your app lol so you owe me this answer)</description>
		<content:encoded><![CDATA[<p>Hey, great blog post, maybe only one of its kind on the Internet&#8230;?</p>
<p>Anyways, I&#8217;ve managed to block images from loading in my UIWebView, but in their place I have those ugly little blue squares with a question mark.</p>
<p>Any suggestions on how to just get a blank square instead of the little blue placeholder?</p>
<p>Thanks in advance (BTW I bought your app lol so you owe me this answer)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Taeyun Kim</title>
		<link>http://www.icab.de/blog/2009/08/18/url-filtering-with-uiwebview-on-the-iphone/comment-page-1/#comment-3471</link>
		<dc:creator>Taeyun Kim</dc:creator>
		<pubDate>Tue, 13 Jul 2010 04:49:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=35#comment-3471</guid>
		<description>It&#039;s a great article.
BTW, I want to supply alternative data &#039;asynchronously&#039; from the other web sites rather than empty or local one synchronously. But the above method can only supply data synchronously since NSCachedURLResponse object must have the data before cachedResponseForRequest function returns.
I hooked NSURLConnection&#039;s init*() methods (ex: initWithRequest) using Objective C&#039;s method swizzling, but the methods were not called. WebView does not seem to use NSURLConnection at all.
If you have any suggestion or hint, please let me know.
Thanks in advance.</description>
		<content:encoded><![CDATA[<p>It&#8217;s a great article.<br />
BTW, I want to supply alternative data &#8216;asynchronously&#8217; from the other web sites rather than empty or local one synchronously. But the above method can only supply data synchronously since NSCachedURLResponse object must have the data before cachedResponseForRequest function returns.<br />
I hooked NSURLConnection&#8217;s init*() methods (ex: initWithRequest) using Objective C&#8217;s method swizzling, but the methods were not called. WebView does not seem to use NSURLConnection at all.<br />
If you have any suggestion or hint, please let me know.<br />
Thanks in advance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alexander</title>
		<link>http://www.icab.de/blog/2009/08/18/url-filtering-with-uiwebview-on-the-iphone/comment-page-1/#comment-3414</link>
		<dc:creator>Alexander</dc:creator>
		<pubDate>Fri, 09 Jul 2010 20:14:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=35#comment-3414</guid>
		<description>@Paul
I&#039;m not exactly sure what exactly you&#039;re doing.  If you start your own request within the cachedResponseForRequest method, you may have some problems if your request is done asynchronically, because then the WebView that has called the cachedResponseForRequest method will process the image before it is actually loaded, and so you only get the missing image placeholder. </description>
		<content:encoded><![CDATA[<p>@Paul<br />
I&#8217;m not exactly sure what exactly you&#8217;re doing.  If you start your own request within the cachedResponseForRequest method, you may have some problems if your request is done asynchronically, because then the WebView that has called the cachedResponseForRequest method will process the image before it is actually loaded, and so you only get the missing image placeholder.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul</title>
		<link>http://www.icab.de/blog/2009/08/18/url-filtering-with-uiwebview-on-the-iphone/comment-page-1/#comment-3413</link>
		<dc:creator>Paul</dc:creator>
		<pubDate>Fri, 09 Jul 2010 18:44:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=35#comment-3413</guid>
		<description>I have done something very similar here with subclassing NSURLCache. I&#039;m trying to route http:// image requests through this NSURLCache method which only apparently tries to cache things that are in the bundle(?), so I replaced http:// with http___ in my view which triggers cachedResponseForRequest. Then I switch out the http___ with http:// and do the request and cache it to disk with Three20&#039;s TTURLRequest. I am able to get the data from my request and put together the cache response, but the image which I&#039;m trying to cache appears only as a missing image from the UIWebView that is requesting it.  Has anyone run into this before? It&#039;s driving me batty. I can post code if necessary.

Thanks
Paul</description>
		<content:encoded><![CDATA[<p>I have done something very similar here with subclassing NSURLCache. I&#8217;m trying to route http:// image requests through this NSURLCache method which only apparently tries to cache things that are in the bundle(?), so I replaced http:// with http___ in my view which triggers cachedResponseForRequest. Then I switch out the http___ with http:// and do the request and cache it to disk with Three20&#8242;s TTURLRequest. I am able to get the data from my request and put together the cache response, but the image which I&#8217;m trying to cache appears only as a missing image from the UIWebView that is requesting it.  Has anyone run into this before? It&#8217;s driving me batty. I can post code if necessary.</p>
<p>Thanks<br />
Paul</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alexander</title>
		<link>http://www.icab.de/blog/2009/08/18/url-filtering-with-uiwebview-on-the-iphone/comment-page-1/#comment-2294</link>
		<dc:creator>Alexander</dc:creator>
		<pubDate>Mon, 12 Apr 2010 18:02:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=35#comment-2294</guid>
		<description>@m
Reloading via [webView reload] will bypass the cache and so it will always load everything. But if you reload a web page via javascript, you can reload the page in a way, so that the cache is still used and you can still filter out requests:
[webView stringByEvaluatingJavaScriptFromString:@&quot;location.replace(location.href)&quot;]

Another problem is that internally UIWebView uses memory caches as well, so even if you empty the NSURLCache, you may still get the &quot;old&quot; states because of the internal memory caches. 

In a normal web browser context where filters are usually used to filter out banner ads, the internal caches are not a big deal. The filters are usually more or less static and won&#039;t change.   But if the filters do change often, you may get in trouble...</description>
		<content:encoded><![CDATA[<p>@m<br />
Reloading via [webView reload] will bypass the cache and so it will always load everything. But if you reload a web page via javascript, you can reload the page in a way, so that the cache is still used and you can still filter out requests:<br />
[webView stringByEvaluatingJavaScriptFromString:@"location.replace(location.href)"]</p>
<p>Another problem is that internally UIWebView uses memory caches as well, so even if you empty the NSURLCache, you may still get the &#8220;old&#8221; states because of the internal memory caches. </p>
<p>In a normal web browser context where filters are usually used to filter out banner ads, the internal caches are not a big deal. The filters are usually more or less static and won&#8217;t change.   But if the filters do change often, you may get in trouble&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: m</title>
		<link>http://www.icab.de/blog/2009/08/18/url-filtering-with-uiwebview-on-the-iphone/comment-page-1/#comment-2287</link>
		<dc:creator>m</dc:creator>
		<pubDate>Mon, 12 Apr 2010 00:55:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=35#comment-2287</guid>
		<description>oh my previous post didnt work.
When I display a webview where I dont want filtering to take place, I set a global and then bypass my filtering. Problem is that if that page uses something I&#039;ve previously filtered out it doesnt reloaded it. So I&#039;m using [webView reload] to make that happen (with 2 page loads - ugh!). I was hoping I could use removeAllCachedResponses to tell the cache to forget what I&#039;ve filtered out previously.</description>
		<content:encoded><![CDATA[<p>oh my previous post didnt work.<br />
When I display a webview where I dont want filtering to take place, I set a global and then bypass my filtering. Problem is that if that page uses something I&#8217;ve previously filtered out it doesnt reloaded it. So I&#8217;m using [webView reload] to make that happen (with 2 page loads &#8211; ugh!). I was hoping I could use removeAllCachedResponses to tell the cache to forget what I&#8217;ve filtered out previously.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: m</title>
		<link>http://www.icab.de/blog/2009/08/18/url-filtering-with-uiwebview-on-the-iphone/comment-page-1/#comment-2286</link>
		<dc:creator>m</dc:creator>
		<pubDate>Mon, 12 Apr 2010 00:52:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=35#comment-2286</guid>
		<description>i would have expected using [ NSURLCache removeAllCachedResponses] would have cleared everything I&#039;ve already filtered out. And if I disable filtering, it would download the entire page. But it doesnt appear to be so.
If I use [webView reload] it redownloads everything. But I really wanted to avoid to 2 page loads for a UIWebView where I dont want filtering to take place.</description>
		<content:encoded><![CDATA[<p>i would have expected using [ NSURLCache removeAllCachedResponses] would have cleared everything I&#8217;ve already filtered out. And if I disable filtering, it would download the entire page. But it doesnt appear to be so.<br />
If I use [webView reload] it redownloads everything. But I really wanted to avoid to 2 page loads for a UIWebView where I dont want filtering to take place.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alexander</title>
		<link>http://www.icab.de/blog/2009/08/18/url-filtering-with-uiwebview-on-the-iphone/comment-page-1/#comment-2269</link>
		<dc:creator>Alexander</dc:creator>
		<pubDate>Sat, 10 Apr 2010 21:50:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=35#comment-2269</guid>
		<description>@m
No, you can&#039;t see from which UIWebView the request came from.</description>
		<content:encoded><![CDATA[<p>@m<br />
No, you can&#8217;t see from which UIWebView the request came from.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: m</title>
		<link>http://www.icab.de/blog/2009/08/18/url-filtering-with-uiwebview-on-the-iphone/comment-page-1/#comment-2265</link>
		<dc:creator>m</dc:creator>
		<pubDate>Sat, 10 Apr 2010 14:45:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=35#comment-2265</guid>
		<description>is there a way to know which UIWebView the request came from? So we could filter for some webviews, but not others?</description>
		<content:encoded><![CDATA[<p>is there a way to know which UIWebView the request came from? So we could filter for some webviews, but not others?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: m</title>
		<link>http://www.icab.de/blog/2009/08/18/url-filtering-with-uiwebview-on-the-iphone/comment-page-1/#comment-2256</link>
		<dc:creator>m</dc:creator>
		<pubDate>Fri, 09 Apr 2010 22:05:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=35#comment-2256</guid>
		<description>wow. brilliant - works like a charm - you can filter out whatever you want!
Thanks again!</description>
		<content:encoded><![CDATA[<p>wow. brilliant &#8211; works like a charm &#8211; you can filter out whatever you want!<br />
Thanks again!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
