<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" 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/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Coding Ventures</title>
	
	<link>http://www.codingventures.com</link>
	<description>Kerem Karatal’s musings on code, technology and more…</description>
	<lastBuildDate>Mon, 23 Nov 2009 20:39:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/CodingVentures" /><feedburner:info uri="codingventures" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Eight months later #2 iPhone app for kids in UK AppStore</title>
		<link>http://feedproxy.google.com/~r/CodingVentures/~3/gXLBo_WLCHs/</link>
		<comments>http://www.codingventures.com/2009/11/eight-months-later-2-iphone-app-for-kids-in-uk-appstore/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 20:38:51 +0000</pubDate>
		<dc:creator>keremk</dc:creator>
				<category><![CDATA[IPhone]]></category>
		<category><![CDATA[IPhone Applications]]></category>
		<category><![CDATA[Apps for Kids]]></category>
		<category><![CDATA[appstore]]></category>
		<category><![CDATA[coloring book]]></category>
		<category><![CDATA[Coloring Fun]]></category>

		<guid isPermaLink="false">http://www.codingventures.com/?p=181</guid>
		<description><![CDATA[Can an app sit 8 months idle in the AppStore, and all of a sudden become the #2 app? With no updates? No advertising? I guess the answer is yes! My coloring book app, Coloring Fun, is now the #2 app in Games/Kids category in the UK AppStore. Moreover it is indeed #43 in overall [...]]]></description>
			<content:encoded><![CDATA[<p>Can an app sit 8 months idle in the AppStore, and all of a sudden become the #2 app? With no updates? No advertising? I guess the answer is yes! My coloring book app, <a href="http://www.codingventures.com/products/">Coloring Fun</a>, is now the #2 app in Games/Kids category in the UK AppStore. Moreover it is indeed #43 in overall games category and #79 in the general apps category!! And the fun does not stop there. It is #3 in France, #5 in Italy, #7 in Canada, #7 in Australia and #17 in Germany&#8230;  After 8 months?? And more importantly is there really a significant market for applications for kids in the AppStore?</p>

<p><span id="more-181"></span>
So how did that happen? I have pretty much stopped checking my iTunes reports after 8 months of steady but lackluster performance. But then it all changed. I was writing a reply back to my friend about how my app was doing, and decided to include actual stats and so I logged in and downloaded my daily report, and immediately got struck by a WTF moment. All of a suddenly there was this &#8220;huge&#8221; spike and it was all coming from outside US.</p>

<p style="text-align: center;"><img class="size-full wp-image-183 aligncenter" src="http://www.codingventures.com/wp-content/uploads/2009/11/AppStore1.png" alt="AppStore Sales Spike" width="559" height="501" /></p>

<p>I first thought it was a glitch, but then I realized it was not. It was indeed happening for the last 3 weeks, without me knowing anything about it. In fact the funny thing is, I stopped checking regularly around the time just before the spike seemed to have happened.</p>

<p>Anyways a <a href="http://www.pocketpixels.com/ColorSplash.html">good colleague of mine</a> pointed out that it was indeed featured in the apps for kids category over in Europe.</p>

<p><img class="size-full wp-image-193 alignnone" src="http://www.codingventures.com/wp-content/uploads/2009/11/appsforkids1.png" alt="Apps For Kids Promotion" width="689" height="467" /></p>

<p style="text-align: left;">This mainly speaks to the power of Apple&#8217;s marketing. Below is a pie chart that shows country distributions for Coloring Fun&#8217;s sales. US is still the second biggest but it took 8 months of sales to get there, whereas UK got to %26 in just less than 3 weeks.</p>

<p style="text-align: center;"><img class="size-full wp-image-198    aligncenter" src="http://www.codingventures.com/wp-content/uploads/2009/11/CountryDistribution.png" alt="Country Distribution" width="380" height="516" /></p>

<p style="text-align: left;"></p>

<p style="text-align: left;"></p>

<p style="text-align: left;">Frankly I was never really sure for the potential for an application for kids. I used this more as a learning tool for understanding the iPhone SDK, something I can relatively quickly build and post it to the appstore. I did not really spend any time marketing it, even to the extent of submitting it to review sites. I guess this demonstrates that there indeed is a market for kid&#8217;s games. Especially the fact that being #2 in a kids game translates to #43 in overall games category and #79 in overall apps category shows that kid&#8217;s games are actually a substantial piece of the overall application sales traffic (at least in UK). And it also shows that a substantial group of people are indeed comfortable letting their young children play with their iPhones or iPod Touches.</p>

<p style="text-align: left;">Well now I am interested. I am currently working on updating the app as a first step. And we will see how this goes&#8230;</p>
<img src="http://feeds.feedburner.com/~r/CodingVentures/~4/gXLBo_WLCHs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.codingventures.com/2009/11/eight-months-later-2-iphone-app-for-kids-in-uk-appstore/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://www.codingventures.com/2009/11/eight-months-later-2-iphone-app-for-kids-in-uk-appstore/</feedburner:origLink></item>
		<item>
		<title>Image manipulation and drawing using Quartz in the background threads</title>
		<link>http://feedproxy.google.com/~r/CodingVentures/~3/9XQ_7h_2Q0o/</link>
		<comments>http://www.codingventures.com/2009/08/image-manipulation-and-drawing-using-quartz-in-the-background-threads/#comments</comments>
		<pubDate>Mon, 03 Aug 2009 22:33:53 +0000</pubDate>
		<dc:creator>keremk</dc:creator>
				<category><![CDATA[IPhone]]></category>
		<category><![CDATA[CoreGraphics]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[quartz]]></category>
		<category><![CDATA[thread safety]]></category>
		<category><![CDATA[threading]]></category>
		<category><![CDATA[UIKit]]></category>

		<guid isPermaLink="false">http://www.codingventures.com/?p=166</guid>
		<description><![CDATA[In many of the iPhone samples, the recommended way of drawing onto off-screen bitmap context begins by getting a bitmap context using the UIGraphicsBeginImageContext() API call. This works great if your drawing code is in the main UI thread, but in some cases you may want to do some processing in a background thread as [...]]]></description>
			<content:encoded><![CDATA[<p>In many of the iPhone samples, the recommended way of drawing onto off-screen bitmap context begins by getting a bitmap context using the <code>UIGraphicsBeginImageContext()</code> API call. This works great if your drawing code is in the main UI thread, but in some cases you may want to do some processing in a background thread as well. The prime candidate for this is, when you download an image in a background thread and do some resizing/cropping shadows, borders on that image. You would still want to do that in the background thread in order not to block the UI thread and present a smooth experience. That is exactly what I was doing in my latest project (which BTW you can see the work in progress <a href="http://github.com/keremk/CViPhoneLibrary/tree/master">here</a>).
<span id="more-166"></span></p>

<p>The code works most of the time if you use the <code>UIGraphicsBeginImageContext</code>, but then crashes randomly at some random CoreGraphics calls. The culprit in this case sounded like it was some thread safety issue, and turns out it indeed was. As documented in the <a href="http://developer.apple.com/iPhone/library/documentation/UIKit/Reference/UIKitFunctionReference/Reference/reference.html#//apple_ref/c/func/UIGraphicsBeginImageContext">SDK</a>, when this API call is made, the drawing environment is pushed onto the graphics context stack immediately. And that seems to be what is causing our threading issues. The context stack becomes shared between the UI thread which does its regular drawing code and the background thread which does the background image manipulation.</p>

<p>Luckily fixing this problem is not hard. All you need to do is to stop using the UIKit APIs and go back to the lower level Quartz APIs.</p>


<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">    CGColorSpaceRef colorSpaceRef <span style="color: #002200;">=</span> CGColorSpaceCreateDeviceRGB<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>; 
    CGContextRef context <span style="color: #002200;">=</span> CGBitmapContextCreate<span style="color: #002200;">&#40;</span><span style="color: #a61390;">NULL</span>, size.width, size.height,
                                                 BITS_PER_COMPONENT,
                                                 NUM_OF_COMPONENTS <span style="color: #002200;">*</span> size.width,
                                                 colorSpaceRef,
                                                 kCGImageAlphaPremultipliedLast<span style="color: #002200;">&#41;</span>;
    CGColorSpaceRelease<span style="color: #002200;">&#40;</span>colorSpaceRef<span style="color: #002200;">&#41;</span>;
    CGRect rect <span style="color: #002200;">=</span> CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0.0</span>, <span style="color: #2400d9;">0.0</span>, size.width, size.height<span style="color: #002200;">&#41;</span>;
    CGContextClearRect<span style="color: #002200;">&#40;</span>context, rect<span style="color: #002200;">&#41;</span>;
&nbsp;
    <span style="color: #11740a; font-style: italic;">// Do your drawing and image manipulation..</span>
&nbsp;
    CGImageRef cgImage <span style="color: #002200;">=</span> CGBitmapContextCreateImage<span style="color: #002200;">&#40;</span>context<span style="color: #002200;">&#41;</span>;
    UIImage <span style="color: #002200;">*</span>image <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIImage imageWithCGImage<span style="color: #002200;">:</span>cgImage<span style="color: #002200;">&#93;</span>;
    CGImageRelease<span style="color: #002200;">&#40;</span>cgImage<span style="color: #002200;">&#41;</span>;
    CGContextRelease<span style="color: #002200;">&#40;</span>context<span style="color: #002200;">&#41;</span>;</pre></div></div>

<img src="http://feeds.feedburner.com/~r/CodingVentures/~4/9XQ_7h_2Q0o" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.codingventures.com/2009/08/image-manipulation-and-drawing-using-quartz-in-the-background-threads/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		<feedburner:origLink>http://www.codingventures.com/2009/08/image-manipulation-and-drawing-using-quartz-in-the-background-threads/</feedburner:origLink></item>
		<item>
		<title>Great Cocoa conference on the other side of the Atlantic</title>
		<link>http://feedproxy.google.com/~r/CodingVentures/~3/Xb3RoVl5lK0/</link>
		<comments>http://www.codingventures.com/2009/04/great-cocoa-conference-on-the-other-side-of-the-atlantic/#comments</comments>
		<pubDate>Mon, 13 Apr 2009 00:41:31 +0000</pubDate>
		<dc:creator>keremk</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[conference]]></category>
		<category><![CDATA[NSConference]]></category>

		<guid isPermaLink="false">http://www.codingventures.com/?p=137</guid>
		<description><![CDATA[The Mac Developer Network with Steve Scott(Scotty) and Tim Isted are hosting a great conference, called NSConference, in UK this week. I wish I could be there as well, but it is a bit of a hike for me to be there in person. It would be great if they can make some of the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.mac-developer-network.com/">The Mac Developer Network</a> with Steve Scott(Scotty) and Tim Isted are hosting a great conference, called NSConference, in UK this week. I wish I could be there as well, but it is a bit of a hike for me to be there in person. It would be great if they can make some of the materials available online after the show.</p>

<p><a href="http://www.nsconference.com/index.html" style="display:block;margin-left:auto; margin-right:auto; width:468px; "><img src="http://www.nsconference.com/images/nsconferencebanner.jpg" alt="NSConference 16-17th April 2009, Hatfield, UK" /></a>
<span id="more-137"></span></p>

<p>The quality of the <a href="http://www.nsconference.com/sessions/index.html">listed session topics</a> are very high, and those are definitely not the same sort of information you can find in the upcoming <a href="http://developer.apple.com/wwdc/sessions/">WWDC 2009</a>. Amongst them, the below 2 sessions sounded especially interesting to me: (along with my humble suggestions for additional content)</p>

<p><strong>Designing and Developing Custom Cocoa Controls (Matt Gemmell):</strong> There is surprisingly very little information in the form of guidelines, best practices on this topic for both Cocoa and Cocoa Touch programming. Matt Gemmell has quite a few <a href="http://mattgemmell.com/source">open source controls</a>, so I am sure it would be great to hear about his experience. Even though it is not mentioned in his abstract, I hope that he can also touch a little bit on building Interface Builder plugins for those custom controls. But if not, <a href="http://developer.apple.com/documentation/DeveloperTools/Conceptual/IBPlugInGuide/Introduction/Introduction.html">the Apple docs</a> on IBPlugin are comprehensive as well.</p>

<p><strong>Foundations of Objective-C (Andre Pang): </strong>The best way to really master a language/framework is to go deep into its inner workings. Especially meta-programming is a very powerful tool, once you understand the underlying object model and runtime of that language. Frameworks like Core Data are built on top of the meta-programming principles. It would also be great to also briefly compare it to either Ruby or Python. There is also a pretty interesting screencast from <a href="http://peepcode.com/">PeepCode</a> titled <a href="https://peepcode.com/products/objective-c-for-rubyists">Objective C for Rubyists</a> that approaches Objective C from the perspective of Ruby.</p>
<img src="http://feeds.feedburner.com/~r/CodingVentures/~4/Xb3RoVl5lK0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.codingventures.com/2009/04/great-cocoa-conference-on-the-other-side-of-the-atlantic/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://www.codingventures.com/2009/04/great-cocoa-conference-on-the-other-side-of-the-atlantic/</feedburner:origLink></item>
		<item>
		<title>More useful open source libraries for iPhone development</title>
		<link>http://feedproxy.google.com/~r/CodingVentures/~3/IrqyNrxsIDI/</link>
		<comments>http://www.codingventures.com/2009/04/more-useful-open-source-libraries-for-iphone-development/#comments</comments>
		<pubDate>Fri, 10 Apr 2009 09:55:46 +0000</pubDate>
		<dc:creator>keremk</dc:creator>
				<category><![CDATA[IPhone]]></category>
		<category><![CDATA[ActiveResource]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Facebook Connect]]></category>
		<category><![CDATA[HTTP Server]]></category>
		<category><![CDATA[OAuth]]></category>
		<category><![CDATA[Regex]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[SMTP]]></category>
		<category><![CDATA[Twitter API]]></category>
		<category><![CDATA[UIColor]]></category>
		<category><![CDATA[Unit Test]]></category>

		<guid isPermaLink="false">http://www.codingventures.com/?p=116</guid>
		<description><![CDATA[Back in December 2008, I wrote a blog entry that listed some of the very useful open source libraries that are available for the iPhone. Since then, I bumped into more libraries and some new ones are also added. Here is the list: Social APIs: Facebook Connect: Well finally the Facebook Connect is now available [...]]]></description>
			<content:encoded><![CDATA[<p>Back in December 2008, I wrote a <a href="http://www.codingventures.com/2008/12/useful-open-source-libraries-for-iphone-development/">blog entry</a> that listed some of the very useful open source libraries that are available for the iPhone. Since then, I bumped into more libraries and some new ones are also added. Here is the list:
<span id="more-116"></span></p>

<h1>Social APIs:</h1>

<p><a href="http://developers.facebook.com/connect_iphone.php">Facebook Connect</a>: Well finally the Facebook Connect is now available for the iPhone. Don&#8217;t miss the <a href="http://vimeo.com/3616452">5 minute introduction</a> to implement Facebook Connect on the iPhone.</p>

<p><a href="http://mattgemmell.com/2008/02/22/mgtwitterengine-twitter-from-cocoa">Twitter</a>: Looks like I missed this one in my last post. This is written by <a href="http://mattgemmell.com/">Matt Legend Gemmell</a>. He has a lot of other <a href="http://mattgemmell.com/source">open source code</a> on his site that is used by a <a href="http://mattgemmell.com/featured-apps">long list</a> of popular Mac apps. Note that Twitter is slowly phasing in <a href="http://oauth.net/">OAuth based authentication</a> and this library does not yet support that. And that brings us to &#8230;</p>

<p><a href="http://code.google.com/p/mpoauthconnection/">OAuth</a>: This is a library written by <a href="http://matrixPointer.com/karl/">Karl Adam</a> both for the Mac and the iPhone. In order to make OAuth work on the iPhone, you would need to host UIWebView so that users can authorize your app. Karl described using OAuth specifically for the iPhone <a href="http://matrixPointer.com/karl/posts/mpoauth-on-the-iphone-mpoauthmobile">here</a>.</p>

<h1>Networking and Web Service client libraries:</h1>

<p><a href="http://code.google.com/p/cocoahttpserver/">HTTP Server</a>: So you need a small HTTP server running on your iPhone. (Perhaps to communicate with another phone?) Well you are in luck. There is a Cocoa based HTTP server originally for the Mac, that now also works on the iPhone. Check out their <a href="http://code.google.com/p/cocoahttpserver/downloads/list">sample</a> for the iPhone.</p>

<p><a href="http://code.google.com/p/skpsmtpmessage/">Quick SMTP client</a> : May be you don&#8217;t want to wait for iPhone 3.0 for full UI based email support in your app. Or may be you need something with no UI. This is a quick SMTP client to send one-off emails from your app.</p>

<p><a href="http://allseeing-i.com/ASIHTTPRequest/">HTTP wrapper &#8211; ASIHTTPRequest</a>: Here is a great wrapper around CFNetwork APIs to do HTTP requests. It supports all of GET/POST/PUT/DELETE requests, cookies, Basic/Digest/NTLM authentication support, GZIP for response data and more.</p>

<p><a href="http://github.com/yfactorial/objectiveresource/tree/master">Restful Client, ObjectiveResource</a>: This is an interesting library. It is an implementation of <a href="http://api.rubyonrails.org/classes/ActiveResource/Base.html">ActiveResource</a> for ObjectiveC. Basically it attempts to simplify communicating with the RESTful servers, if you choose to have a RESTful server implementation in the back end. The project is very active and you can read more about it on <a href="http://iphoneonrails.com/">iPhoneOnRails.com</a>.</p>

<h1>Image processing:</h1>

<p><a href="http://code.google.com/p/simple-iphone-image-processing/">Simple Image Processing</a>: CoreImage and CoreImage filters are unfortunately not available for the iPhone. However there is a simple open source library for the iPhone that performs some image processing tasks like edge detection, gaussian blurs, histogram equalization etc.</p>

<h1>Maps:</h1>

<p><a href="http://code.google.com/p/route-me/">Route Me</a>: Again if you can&#8217;t wait for the 3.0 release, or if you want to ensure your app works downlevel, or if you like to use other alternative tilesets from <a href="http://maps.live.com/">Microsoft Virtual Earth</a>, <a href="http://www.openstreetmap.org/index.html">Open Street Map</a> or <a href="http://www.cloudmade.com/">CloudMade</a>, then this library is for you.</p>

<h1>Plotting and graphing:</h1>

<p><a href="http://code.google.com/p/core-plot/">Core Plot</a>: This is another very interesting open source project, that is planning to provide 2D data visualization. This is still in its early stages, but you can check-out source code from the trunk and start playing.</p>

<h1>Utilities, toolkits, UI widgets:</h1>

<p><a href="http://github.com/joehewitt/three20/tree/master">Three20</a>: This is <a href="http://www.joehewitt.com/">Joe Hewitt&#8217;s</a> collection of IPhone UI classes that were originally seen in the <a href="http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=284882215&amp;mt=8">iPhone Facebook app</a>. Includes things like an improved photo viewer, Internet aware high performance table view controllers and other utility classes. Very useful stuff. He also very recently added some CSS-like styling support.</p>

<p><a href="http://github.com/ars/uicolor-utilities/tree/master">UIColor Utilities</a>: Some very useful helper method additions for the UIColor to directly handle RGBA to UIColor additions, additional named colors, color space helpers etc.</p>

<p><a href="http://regexkit.sourceforge.net/RegexKitLite/">Regex &#8211; RegexKitLite</a>: Arguably one of the biggest omissions from a modern framework like Cocoa Touch, is the lack of a built-in support for regular expressions. The upcoming <a href="http://arstechnica.com/apple/guides/2009/04/cocoa-dev-the-joy-of-nspredicates-and-matching-strings.ars">NSPredicate</a> support in 3.0, will bring advanced string searching but it is still not regex. <a href="http://regexkit.sourceforge.net/">RegexKit</a> is a 3rd party open source library for the Mac OS X. <a href="http://regexkit.sourceforge.net/RegexKitLite/">RegexKitLite</a> is a lighter weight version of RegexKit that works on the iPhone.</p>

<p><a href="http://code.google.com/p/plcrashreporter/">Plausible Crash Reporter</a>: So you want to know if and why your apps are crashing out on the field. This library records the crash info on disk and then the next time your app launches, you can <a href="http://plcrashreporter.googlecode.com/svn/tags/plcrashreporter-1.0-rc2/Documentation/API/example_usage_iphone.html">send the crash info</a> back to your server to further analyze.</p>

<p><a href="http://github.com/keremk/iphone-static-library-project-template/tree/master">Project and file templates for static libraries</a>: Well this last one is from me. There is a more <a href="http://www.codingventures.com/2009/04/xcode-templates-for-iphone-static-libraries-with-unit-testing/">detailed blog post</a> on this one.</p>

<p>So this is it for now. Happy code sharing!</p>
<img src="http://feeds.feedburner.com/~r/CodingVentures/~4/IrqyNrxsIDI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.codingventures.com/2009/04/more-useful-open-source-libraries-for-iphone-development/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		<feedburner:origLink>http://www.codingventures.com/2009/04/more-useful-open-source-libraries-for-iphone-development/</feedburner:origLink></item>
		<item>
		<title>XCode templates for iPhone static libraries with unit testing</title>
		<link>http://feedproxy.google.com/~r/CodingVentures/~3/ckXceGBZ3Vg/</link>
		<comments>http://www.codingventures.com/2009/04/xcode-templates-for-iphone-static-libraries-with-unit-testing/#comments</comments>
		<pubDate>Thu, 09 Apr 2009 08:10:59 +0000</pubDate>
		<dc:creator>keremk</dc:creator>
				<category><![CDATA[IPhone]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Google Toolbox for Mac]]></category>
		<category><![CDATA[OCMock]]></category>
		<category><![CDATA[OCUnit]]></category>
		<category><![CDATA[Unit Test]]></category>
		<category><![CDATA[xcode]]></category>

		<guid isPermaLink="false">http://www.codingventures.com/?p=85</guid>
		<description><![CDATA[Currently the only way to create re-usable code amongst different projects for the iPhone platform is to create static libraries. 3rd party frameworks (as in Mac OS X) are not supported in the iPhone SDK. Also setting up unit testing, which is a crucial part of building re-usable libraries of course, is not that trivial. [...]]]></description>
			<content:encoded><![CDATA[<p>Currently the only way to create re-usable code amongst different projects for the iPhone platform is to create static libraries. 3rd party frameworks (as in Mac OS X) are not supported in the iPhone SDK. Also setting up unit testing, which is a crucial part of building re-usable libraries of course, is not that trivial.</p>

<p>To help building static libraries for the iPhone, I decided to create a project template and file template. The project template includes 2 targets. One is the actual static library itself and the other is a unit test target. The file template simplifies creating unit test classes, by including the necessary header files and boiler plate code. I have included the <a href="http://code.google.com/p/google-toolbox-for-mac/wiki/iPhoneUnitTesting">Google Toolbox for Mac&#8217;s iPhone unit testing facilities</a> and the <a href="http://www.mulle-kybernetik.com/software/OCMock/">OCMock framework</a> in these templates.</p>

<p>The source code for the templates are checked into <a href="http://github.com/keremk/iphone-static-library-project-template/tree/master">my github repository</a>. You can take a look at the instructions to install and use them over there.
<span id="more-85"></span>
Once you create your static library, including that in your application project is quite straightforward. Just follow the below steps to add it to your project file:</p>

<ul>
    <li>Drag and drop the &#8220;your_static_library.xcodeproj&#8221; file to your application project&#8217;s &#8220;Groups &#038; Files&#8221; sidebar. Make sure that &#8220;Copy Items&#8221; is unchecked and &#8220;Reference Type&#8221; is &#8220;Relative to Project&#8221; in the dialog that pops up when you drop the static library project.<img src="http://www.codingventures.com/wp-content/uploads/2009/04/addproject-300x280.png" alt="Add Project Dialog" title="Add Project Dialog" width="300" height="280" class="alignright size-medium wp-image-94" /></li>
    <li>Link your static library to your application project. In this case, select the project you just added, and check the checkbox to the far right for the library target. Leave the unit test target as is.<img src="http://www.codingventures.com/wp-content/uploads/2009/04/link-library.png" alt="Link Library Selection" title="Link Library Selection" width="651" height="479" class="alignright size-full wp-image-113" /></li>
    <li>Add the static library headers to your application project. Double click on your application project to open &#8220;Project Info&#8221; dialog. Switch to the &#8220;Build&#8221; tab and first search for the &#8220;Other Linker Flags&#8221; setting and set it to -ObjC. Then search for the &#8220;Header Search Paths&#8221; setting and set it to the relative path to the header files in your static library.<img src="http://www.codingventures.com/wp-content/uploads/2009/04/project-info.png" alt="Project Info Dialog" title="Project Info Dialog" width="692" height="556" class="alignright size-full wp-image-101" /></li>
    <li>Add your static library as a dependency to your application. This ensures that the your static library project is also compiled when you compile your application. To do this, double click on your application target switch to the &#8220;General Tab&#8221; of the &#8220;Target Info&#8221; dialog. Add the static library target by clicking the + sign in the direct dependencies section.<img src="http://www.codingventures.com/wp-content/uploads/2009/04/dependencies1.png" alt="Project Dependencies" title="Project Dependencies" width="692" height="556" class="alignright size-full wp-image-106" /></li>
</ul>

<p>Now you are ready share your library code with any number of applications you build. You can of course apply the same steps to other <a href="http://www.codingventures.com/2008/12/useful-open-source-libraries-for-iphone-development/">3rd party libraries</a> that you find on the web. Happy application building!</p>
<img src="http://feeds.feedburner.com/~r/CodingVentures/~4/ckXceGBZ3Vg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.codingventures.com/2009/04/xcode-templates-for-iphone-static-libraries-with-unit-testing/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		<feedburner:origLink>http://www.codingventures.com/2009/04/xcode-templates-for-iphone-static-libraries-with-unit-testing/</feedburner:origLink></item>
		<item>
		<title>First iPhone Application – Coloring Fun</title>
		<link>http://feedproxy.google.com/~r/CodingVentures/~3/PEIxbfcSuA0/</link>
		<comments>http://www.codingventures.com/2009/03/first-iphone-application-coloring-fun/#comments</comments>
		<pubDate>Sat, 28 Mar 2009 08:05:00 +0000</pubDate>
		<dc:creator>keremk</dc:creator>
				<category><![CDATA[Announcement]]></category>
		<category><![CDATA[IPhone Applications]]></category>
		<category><![CDATA[appstore]]></category>
		<category><![CDATA[IPhone]]></category>
		<category><![CDATA[kids]]></category>

		<guid isPermaLink="false">http://www.codingventures.com/?p=70</guid>
		<description><![CDATA[My first iPhone application is approved and went live tonight! It is a coloring book application for kids. Once I submitted the application, the approval did not take that long (9 days). However changing from an individual to a company account in ITunes Connect took over 1 month. Anyways now that my account is set [...]]]></description>
			<content:encoded><![CDATA[<p>My first iPhone application is approved and went live tonight! It is a <a href="http://www.codingventures.com/products">coloring book application</a> for kids. Once I submitted the application, the approval did not take that long (9 days). However changing from an individual to a company account in ITunes Connect took over 1 month. Anyways now that my account is set up properly, it should hopefully be faster to submit new applications.</p>

<p>A friend of mine came up with the original idea and also provided me with 10 of the original drawings. My dear wife, Oya Karatal, helped with coloring the drawings and picking the colors for the color palette. And I did the programming.</p>
<img src="http://feeds.feedburner.com/~r/CodingVentures/~4/PEIxbfcSuA0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.codingventures.com/2009/03/first-iphone-application-coloring-fun/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://www.codingventures.com/2009/03/first-iphone-application-coloring-fun/</feedburner:origLink></item>
		<item>
		<title>Useful open source libraries for IPhone Development</title>
		<link>http://feedproxy.google.com/~r/CodingVentures/~3/CGJba8JZqd8/</link>
		<comments>http://www.codingventures.com/2008/12/useful-open-source-libraries-for-iphone-development/#comments</comments>
		<pubDate>Mon, 22 Dec 2008 07:13:50 +0000</pubDate>
		<dc:creator>keremk</dc:creator>
				<category><![CDATA[IPhone]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Flickr API]]></category>
		<category><![CDATA[Game]]></category>
		<category><![CDATA[GDATA]]></category>
		<category><![CDATA[Google Data API]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[OCMock]]></category>
		<category><![CDATA[OCUnit]]></category>
		<category><![CDATA[OpenGL ES]]></category>
		<category><![CDATA[Twitter API]]></category>
		<category><![CDATA[Unit Test]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.codingventures.com/?p=43</guid>
		<description><![CDATA[It&#8217;s been almost 3 months since the IPhone SDK&#8217;s infamous NDA restrictions were lifted, and there are now a good set of open source libraries available for the IPhone. In this post I will go through the ones that I know of one way or another. If you are aware of more high quality open [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been almost 3 months since the IPhone SDK&#8217;s infamous NDA restrictions were lifted, and there are now a good set of open source libraries available for the IPhone. In this post I will go through the ones that I know of one way or another. If you are aware of more high quality open source projects, please let me know in the comments so that I can update this post.
<span id="more-43"></span></p>

<h1>JSON Library</h1>

<p>Currently, there are 3 choices that I know of:</p>

<p><a href="http://code.google.com/p/json-framework/">JSON Framework</a>: I used this one in one of my projects, and did not run into problems. Recently after the update to the new SDK 2.2, you may need to make a quick change to your project as outlined <a href="http://code.google.com/p/json-framework/issues/detail?id=18">at the end of this discussion</a>.</p>

<p><a href="http://code.google.com/p/touchcode/wiki/TouchJSON">Touch JSON</a>: This one is from the same project owners as the <a href="http://code.google.com/p/touchcode/wiki/TouchXML">TouchXML</a>.</p>

<p><a href="http://blakeseely.com/downloads.html">Blake Seely&#8217;s BSJSONAdditions</a>: This one is little older and intended for the Mac originally. According to the author of the JSON Framework a little slower as per his <a href="http://code.google.com/p/json-framework/wiki/Performance">performance benchmarks</a></p>

<h1>DOM XML Library</h1>

<p>IPhone SDK includes an event driven (SAX based) XML parser called <a href="http://developer.apple.com/documentation/Cocoa/Conceptual/XMLParsing/XMLParsing.html">NSXMLParser</a>. But if you need DOM style parser, you are out of luck unless you use the libxml2 library directly. There is no MacOS X equivalent of <a href="http://developer.apple.com/documentation/Cocoa/Conceptual/NSXML_Concepts/NSXML.html">NSXML</a> on the IPhone.</p>

<p>However luckily there are at least 2 options that I know of that you might use if you really need the DOM tree:</p>

<p><a href="http://code.google.com/p/touchcode/wiki/TouchXML">TouchXML</a>: Open source lightweight replacement for Cocoa&#8217;s NSXML cluster of classes based on <a href="http://xmlsoft.org/index.html">libxml2</a>.</p>

<p><a href="http://cocoawithlove.com">Matt Gallagher</a>: Wrote a lightweight wrapper on top of libxml2 and describes this in his <a href="http://cocoawithlove.com/2008/10/using-libxml2-for-parsing-and-xpath.html">blog entry</a>.</p>

<p>However note that in a memory and CPU constrained environment like IPhone, it does make more sense to use an event driven parser (probably why Apple decided not to include NSXML in the first place). There is a recent SDK sample called <a href="http://developer.apple.com/iphone/library/samplecode/XMLPerformance/index.html">XMLPerformance</a> that shows parsing large number of items in an efficient way using both the NSXMLParser and the lower level SAX parser provided in libxml2.</p>

<h1>Google Data APIs</h1>

<p>So you would like to access Picasa, Google Calendar, Google Contacts and more&#8230; Well there is a very comprehensive <a href="http://code.google.com/p/gdata-objectivec-client/">ObjectiveC Client Library</a> that you can include as a static library in your applications.</p>

<h1>Twitter</h1>

<p><a href="http://furbo.org/">Craig Hockenberry</a> of the awesome <a href="http://iconfactory.com/twitterrific/">Twitterific</a> fame, made the source code of the Mobile Twitterific <a href="http://code.google.com/p/mobile-twitterrific/">available</a> to serve as a &#8220;Best Practices&#8221; document. There you can find how to connect to Twitter, get and post tweets etc.</p>

<h1>Flickr</h1>

<p>Unfortunately the well-known <a href="http://lukhnos.org/objectiveflickr/blog/about/">Cocoa API for Flickr</a> is still not ported to the IPhone. However it looks like they are <a href="http://lukhnos.org/objectiveflickr/blog/archives/14">working on porting it to IPhone</a> as of November 2008.</p>

<h1>Game Engines</h1>

<p>There are at least 3 game engines that I know of:</p>

<p><a href="http://code.google.com/p/cocos2d-iphone/">2D Gaming &#8211; Cocos 2D</a>: This one is intended for 2D games, demos and other graphical/interactive applications. It is a port from the Python based cocos2d design. It uses Open ES 1.1, instead of the Quartz 2D and integrates the <a href="http://code.google.com/p/chipmunk-physics">Chipmunk</a> 2d physics engine.</p>

<p><a href="http://code.google.com/p/sio2/">3D Gaming &#8211; SIO2 Interactive</a>: A 3D engine written in C using OpenGL ES.</p>

<p><a href="http://code.google.com/p/oolongengine/">3D Gaming &#8211; Oolong Engine</a>: Mainly written in C++ with some ObjectiveC. Based on OpenGL ES 1.1 and includes the <a href="http://www.bulletphysics.com/Bullet/wordpress/">Bullet 3D physics engine</a>.</p>

<p>You can also take a look at some IPhone game source code:</p>

<p><a href="http://code.google.com/p/tris/">Tris</a>: The source code for the Tetris clone that was <a href="http://twofingerplay.blogspot.com/2008/08/over-for-now.html">pulled out of the Appstore</a> earlier.</p>

<p><a href="http://www.sunsetlakesoftware.com/2008/10/02/molecules-source-code-now-available">Molecules</a>: This is not a game, but serves as a good tutorial for OpenGL ES development.</p>

<h1>Unit Testing and Mock Frameworks</h1>

<p>As of IPhone SDK 2.2, Apple now includes the <a href="http://developer.apple.com/tools/unittest.html">OCUnit</a>. This was discussed in the <a href="http://www.stanford.edu/class/cs193p/cgi-bin/index.php">Stanford IPhone Application Programming course</a> and you can download the <a href="http://cs193p.stanford.edu/downloads/19-UnitTestRuntimeLoc.pdf">presentation</a> and the <a href="http://cs193p.stanford.edu/downloads/19-ObjCPlayground.zip">sample</a>. So right of the bat you are now set up for unit testing, no more excuses.</p>

<p>Google actually has a more comprehensive <a href="http://code.google.com/p/google-toolbox-for-mac/wiki/iPhoneUnitTesting">framework</a> in their <a href="http://code.google.com/p/google-toolbox-for-mac/">Google Toolbox for Mac</a> that even includes support for UI testing.</p>

<p>There is also a <a href="http://www.mockobjects.com/">mock object</a> framework called <a href="http://www.mulle-kybernetik.com/software/OCMock/">OCMock</a> that is designed for MacOS X Cocoa, but with <a href="http://iamthewalr.us/blog/2008/11/10/ocmock-and-the-iphone/">a little bit of work</a> you can get that to work for your IPhone projects.</p>
<img src="http://feeds.feedburner.com/~r/CodingVentures/~4/CGJba8JZqd8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.codingventures.com/2008/12/useful-open-source-libraries-for-iphone-development/feed/</wfw:commentRss>
		<slash:comments>42</slash:comments>
		<feedburner:origLink>http://www.codingventures.com/2008/12/useful-open-source-libraries-for-iphone-development/</feedburner:origLink></item>
		<item>
		<title>7 tips for using UIWebView</title>
		<link>http://feedproxy.google.com/~r/CodingVentures/~3/c-OTDENwylM/</link>
		<comments>http://www.codingventures.com/2008/12/using-uiwebview-to-render-svg-files/#comments</comments>
		<pubDate>Fri, 12 Dec 2008 10:35:38 +0000</pubDate>
		<dc:creator>keremk</dc:creator>
				<category><![CDATA[IPhone]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[SVG]]></category>
		<category><![CDATA[UIWebView]]></category>

		<guid isPermaLink="false">http://www.codingventures.com/?p=31</guid>
		<description><![CDATA[For an IPhone app I have been building, I decided to use the UIWebView to render SVG files, instead of doing the vector rendering myself. I needed to have a way to read-in files generated from a vector authoring tool (Illustrator etc.) and after initially looking for an open-source SVG parsing/rendering engine of some sort, [...]]]></description>
			<content:encoded><![CDATA[<p>For an IPhone app I have been building, I decided to use the UIWebView to render SVG files, instead of doing the vector rendering myself. I needed to have a way to read-in files generated from a vector authoring tool (Illustrator etc.) and after initially looking for an open-source SVG parsing/rendering engine of some sort, I decided on hosting the UIWebView itself instead and use the SVG rendering capability of WebKit. Another option could have been to read in PDF files as PDF is the default meta-file format for Quartz, but I needed programmatic access to each path drawn in the file and it was not apparent to me how I can do that once the PDF is rendered. (Any ideas on that is still welcome of course)</p>

<p>Anyways the point of this post is not really about different options for persisting and reading vector graphic files. I am rather planning to talk a bit about some of the tricky things I found out while trying to use the UIWebView programatically. 
<span id="more-31"></span></p>

<h1>Loading the SVG file from your resources folder</h1>

<p>This one is quite straightforward. You need to get the correct path for your resources folder and the SVG file in that folder, which can be easily accomplished using the below snippet:</p>


<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>filePath <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSBundle</span> mainBundle<span style="color: #002200;">&#93;</span>
	pathForResource<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;filenameWithoutExtension&quot;</span> ofType<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;svg&quot;</span>;
<span style="color: #400080;">NSData</span> <span style="color: #002200;">*</span>svgData <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSData</span> dataWithContentsOfFile<span style="color: #002200;">:</span>filePath<span style="color: #002200;">&#93;</span>;</pre></div></div>


<p>I also wanted to reference the javascript I used in the SVG file, instead of inline embedding. So I made sure that I set the baseURL correctly for the UIWebView to resolve the path to the javascript file in my resources directory:</p>


<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>resourcePath <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSBundle</span> mainBundle<span style="color: #002200;">&#93;</span> resourcePath<span style="color: #002200;">&#93;</span>;
<span style="color: #400080;">NSURL</span> <span style="color: #002200;">*</span>baseURL <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSURL</span> alloc<span style="color: #002200;">&#93;</span> initFileURLWithPath<span style="color: #002200;">:</span>resourcePath isDirectory<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #002200;">&#91;</span>self.webView 	loadData<span style="color: #002200;">:</span>svgData 
	MIMEType<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;image/svg+xml&quot;</span>	
	textEncodingName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;UTF-8&quot;</span> 
	baseURL<span style="color: #002200;">:</span>baseURL<span style="color: #002200;">&#93;</span>;	
<span style="color: #002200;">&#91;</span>baseURL release<span style="color: #002200;">&#93;</span>;</pre></div></div>


<p>However to my surprise the above did not work for locating my script file in the SVG referenced as below:</p>


<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;script type=&quot;text/ecmascript&quot; src=&quot;foo.js&quot;/&gt;</pre></div></div>


<p>Well it turns out the src attribute is not actually in the <a href="http://www.w3.org/TR/SVG11/script.html">SVG 1.1 specification</a> at all?? The way I solved that problem is to write a build script to embed the script inline to the svg file (i.e. a preprocessing step) and make it part of the build process. (More on that in a later post&#8230;)</p>

<h1>UIWebView loading contents when it is off-screen</h1>

<p>Another surprise was trying to be able to load the SVG file when the UIWebView was off-screen. My design hosted the UIWebView inside a UIScrollView and I was loading the current page and caching the next and previous pages to have a smooth transition as I swipe the scrollview. But it turns out UIWebView has an issue with loading when it is off-screen. I.e. it does not render its contents, when it comes back into screen unless you double tap into it. It sounds more like a bug to me.</p>

<p>To solve this problem, I delayed the actual loading of the SVG file till:</p>


<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>scrollViewDidEndDecelerating<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIScrollView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>scrollView</pre></div></div>


<p>for the current view that is becoming visible and I also made sure that once it is loaded when the UIWebView is visible, I don&#8217;t ask it to reload it every time the user swipes the view to left and right.</p>

<h1>Calling a javascript function from Objective-C</h1>

<p>Part of my application is implemented in Javascript and using the DOM to manipulate the SVG document. I need to be able to call some of my Javascript functions from my Objective-C code. This is fairly straightforward and well documented in the UIWebView reference documentation in the SDK. All you need to do is to create an NSString which contains the Javascript function call, and ask the UIWebView to execute it as shown below:</p>


<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>jsCommand <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;setActiveColor(%d, %d, %d);&quot;</span>, 
	redColor, greenColor, blueColor<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>self.webView stringByEvaluatingJavaScriptFromString<span style="color: #002200;">:</span>jsCommand<span style="color: #002200;">&#93;</span>;</pre></div></div>


<h1>Javascript communicating back with Objective-C code</h1>

<p>What happens when you need to call back your Objective-C code from Javascript? Unfortunately at the time of this writing, there is no proper API for this for the IPhone. (See <a href="http://developer.apple.com/documentation/AppleApplications/Conceptual/SafariJSProgTopics/Tasks/ObjCFromJavaScript.html">Apple Documentation</a> for how to do it in MacOS X using WebKit) Fortunately there is a hack, a lot of <a href="http://phonegap.com">projects</a> have been using. It basically involves communication through a custom protocol that you make up to pass some parameters and then parsing those parameters in your Objective C code to call your corresponding Objective-C methods.</p>

<p>Basically you create a protocol like below:</p>


<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">myapp<span style="color: #002200;">:</span>myfunction<span style="color: #002200;">:</span>myparam1<span style="color: #002200;">:</span>myparam2</pre></div></div>


<p>And then in Javascript:</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">document.<span style="color: #660066;">location</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;myapp:&quot;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;myfunction:&quot;</span> <span style="color: #339933;">+</span> param1 <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;:&quot;</span> <span style="color: #339933;">+</span> param2<span style="color: #339933;">;</span></pre></div></div>


<p>Then back in your Objective-C code:</p>


<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>webView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIWebView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>webView2 
	shouldStartLoadWithRequest<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSURLRequest</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>request 
	navigationType<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIWebViewNavigationType<span style="color: #002200;">&#41;</span>navigationType <span style="color: #002200;">&#123;</span>
&nbsp;
	<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>requestString <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>request URL<span style="color: #002200;">&#93;</span> absoluteString<span style="color: #002200;">&#93;</span>;
	<span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>components <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>requestString componentsSeparatedByString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;:&quot;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>components count<span style="color: #002200;">&#93;</span> &gt; <span style="color: #2400d9;">1</span> <span style="color: #002200;">&amp;&amp;</span> 
		<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span>components objectAtIndex<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span> isEqualToString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;myapp&quot;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span>components objectAtIndex<span style="color: #002200;">:</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span> isEqualToString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;myfunction&quot;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> 
		<span style="color: #002200;">&#123;</span>
&nbsp;
			NSLog<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>components objectAtIndex<span style="color: #002200;">:</span><span style="color: #2400d9;">2</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>; <span style="color: #11740a; font-style: italic;">// param1</span>
			NSLog<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>components objectAtIndex<span style="color: #002200;">:</span><span style="color: #2400d9;">3</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>; <span style="color: #11740a; font-style: italic;">// param2</span>
			<span style="color: #11740a; font-style: italic;">// Call your method in Objective-C method using the above...</span>
		<span style="color: #002200;">&#125;</span>
		<span style="color: #a61390;">return</span> <span style="color: #a61390;">NO</span>;
	<span style="color: #002200;">&#125;</span>
&nbsp;
	<span style="color: #a61390;">return</span> <span style="color: #a61390;">YES</span>; <span style="color: #11740a; font-style: italic;">// Return YES to make sure regular navigation works as expected.</span>
<span style="color: #002200;">&#125;</span></pre></div></div>


<p>Hacky: yes. 
Gets the job done: yes</p>

<h1>Disabling the selection flash</h1>

<p>Once you do the above steps, you are basically mostly on your way to have a functioning application that makes use of UIWebView as a component. But as any good IPhone application, you need to add more polish and get rid of the user annoyances.</p>

<p>The first annoyance is, what happens when you tap inside the UIWebView control that is hosting an SVG file. There is a default behavior that happens for all image files, including SVG files. The background of the image (including the border area) flashes quickly to some default grayish color.</p>

<p>Turns out there is a way to turn this off through the use of the WebKit CSS property -webkit-tap-highlight-color, and setting the alpha of the color to 0, in my Javascript code does the trick:</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">document.<span style="color: #660066;">documentElement</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">webkitTapHighlightColor</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;rgba(0,0,0,0)&quot;</span><span style="color: #339933;">;</span></pre></div></div>


<h1>Disabling the &#8220;action&#8221; pop-up</h1>

<p>The second thing I needed to disable is the &#8220;action&#8221; popup that appears if you tap and hold the contents of the UIWebView for a few seconds. This is also controlled through a CSS property called -webkit-touch-callout, and setting that to &#8220;none&#8221; in this case does the trick:</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">document.<span style="color: #660066;">documentElement</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">webkitTouchCallout</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;none&quot;</span><span style="color: #339933;">;</span></pre></div></div>


<h1>Disabling default zoom effect</h1>

<p>The final user annoyance I had was the zooming effect that happens by default, when you double tap the content area. Well for many applications this may be a desired effect, but in my case, I needed to disable the zooming. I was hoping that there is another CSS property that is something like webkit-disable-doubletap-zoom but unfortunately no such property exists (at least as of this writing.)</p>

<p>The only other idea I came up with was to be able to detect double tapping and calling the standard <a href="https://developer.mozilla.org/En/DOM:event.preventDefault">preventDefault</a> on the event when that touch happens in my Javascript code. But it turns out that SVG DOM does not at the moment fully implement the <a href="http://www.sitepen.com/blog/2008/07/10/touching-and-gesturing-on-the-iphone/">touch and gesture events</a>. You should be able to use those when you are hosting regular HTML though.</p>

<p>The final approach I came up with was to be able to intercept the touch events before they even reach UIWebView and stop them in my Objective-C code. To do this, you need to read a bit more about how the <a href="http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/EventHandling/chapter_5_section_3.html">touch events are routed in Cocoa</a>. (Requires login to the IPhone Dev Center) Basically the idea is to override the hit testing part of the UIWebView and detect the double tap there. In order to that I subclassed UIWebView and overrode the hitTest method in my implementation. Other than that I keep it up the superclass to do the rest.</p>


<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span>UIView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>hitTest<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CGPoint<span style="color: #002200;">&#41;</span>point withEvent<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIEvent <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>event <span style="color: #002200;">&#123;</span>	
	<span style="color: #400080;">NSSet</span> <span style="color: #002200;">*</span>touches <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>event allTouches<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">BOOL</span> forwardToSuper <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;
	<span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span>UITouch <span style="color: #002200;">*</span>touch <span style="color: #a61390;">in</span> touches<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>touch tapCount<span style="color: #002200;">&#93;</span> &gt;<span style="color: #002200;">=</span> <span style="color: #2400d9;">2</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
			<span style="color: #11740a; font-style: italic;">// prevent this </span>
			forwardToSuper <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
		<span style="color: #002200;">&#125;</span>		
	<span style="color: #002200;">&#125;</span>
	<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>forwardToSuper<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
		<span style="color: #11740a; font-style: italic;">//return self.superview;</span>
		<span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>super hitTest<span style="color: #002200;">:</span>point withEvent<span style="color: #002200;">:</span>event<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#125;</span>
	<span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
		<span style="color: #11740a; font-style: italic;">// Return the superview as the hit and prevent</span>
		<span style="color: #11740a; font-style: italic;">// UIWebView receiving double or more taps</span>
		<span style="color: #a61390;">return</span> self.superview;
	<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span></pre></div></div>


<p>So this finally did the trick and I was able to prevent the double tap zooming effect as well.</p>
<img src="http://feeds.feedburner.com/~r/CodingVentures/~4/c-OTDENwylM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.codingventures.com/2008/12/using-uiwebview-to-render-svg-files/feed/</wfw:commentRss>
		<slash:comments>48</slash:comments>
		<feedburner:origLink>http://www.codingventures.com/2008/12/using-uiwebview-to-render-svg-files/</feedburner:origLink></item>
	</channel>
</rss>
