<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	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/"
	>

<channel>
	<title>MK Blog &#187; Coding</title>
	<atom:link href="http://blog.mugunthkumar.com/category/coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.mugunthkumar.com</link>
	<description>iPhone, iPad, Windows Development and Usability Guidelines</description>
	<lastBuildDate>Tue, 29 Jun 2010 06:15:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>iOS4 Issue: NSURLConnection and NSOperation</title>
		<link>http://blog.mugunthkumar.com/coding/ios4-issue-nsurlconnection-and-nsoperation/</link>
		<comments>http://blog.mugunthkumar.com/coding/ios4-issue-nsurlconnection-and-nsoperation/#comments</comments>
		<pubDate>Mon, 21 Jun 2010 13:25:43 +0000</pubDate>
		<dc:creator>Mugunth Kumar</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[ios4]]></category>
		<category><![CDATA[objective c]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://blog.mugunthkumar.com/?p=793</guid>
		<description><![CDATA[Everyone knows NSOperation is easily the best way to automatically gain powerful multi-threading on iOS/Mac platforms. However, recently for one of my apps, I faced a issue where, the NSURLConnection&#8217;s initWithRequest method doesn&#8217;t automatically start even if you forcefully send the &#8220;start&#8221; message. For example the below code works perfectly on iPhone OS 3.1 and [...]


Related posts:<ol><li><a href='http://blog.mugunthkumar.com/coding/consuming-a-restful-service-bit-ly-in-an-iphone-application/' rel='bookmark' title='Permanent Link: Consuming a RESTful Service (bit.ly) in an iPhone Application'>Consuming a RESTful Service (bit.ly) in an iPhone Application</a> <small>bit-ly-rest-api-objective-c Introduction Of late, many programmers who develop for Windows/Linux...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Everyone knows NSOperation is easily the best way to automatically gain powerful multi-threading on iOS/Mac platforms. However, recently for one of my apps, I faced a issue where, the NSURLConnection&#8217;s initWithRequest method doesn&#8217;t automatically start even if you forcefully send the &#8220;start&#8221; message.</p>
<p>For example the below code works perfectly on iPhone OS 3.1 and below but fails on iOS 4.</p>
<p><code>- (void)start<br />
{<br />
    [self willChangeValueForKey:@"isExecuting"];<br />
    _isExecuting = YES;<br />
    [self didChangeValueForKey:@"isExecuting"];</p>
<p>    NSURLRequest * request = [NSURLRequest requestWithURL:_url];<br />
    _connection = [[NSURLConnection alloc] initWithRequest:request<br />
                                                  delegate:self];<br />
}</code></p>
<p>Seems like Apple has made a change where in if the NSURLConnection&#8217;s initWithRequest method is called from a thread that&#8217;s not the main thread, it doesn&#8217;t start downloading the URL contents immediately. The bug fix for this issue is fortunately simple.</p>
<p><code>- (void)start<br />
{<br />
    [self willChangeValueForKey:@"isExecuting"];<br />
    _isExecuting = YES;<br />
    [self didChangeValueForKey:@"isExecuting"];</p>
<p>    NSURLRequest * request = [NSURLRequest requestWithURL:_url];<br />
    _connection = [[NSURLConnection alloc] initWithRequest:request<br />
                                                  delegate:self];</p>
<p>        <em>//iOS 4 bug fix<br />
	if (![NSThread isMainThread])<br />
	{<br />
		[self performSelectorOnMainThread:@selector(start)<br />
							   withObject:nil waitUntilDone:NO];<br />
		return;<br />
	}</em><br />
}</code></p>
<p>Hope this post solves your problem.</p>
<p>&#8211;<br />
Mugunth</p>
<p><map name='google_ad_map_793_8b86e81420c6776e'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/793?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_793_8b86e81420c6776e' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=793&amp;url= http%3A%2F%2Fblog.mugunthkumar.com%2Fcoding%2Fios4-issue-nsurlconnection-and-nsoperation%2F' /></p>

<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-wealth">
<ul class="socials">
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=iOS4+Issue%3A+NSURLConnection+and+NSOperation+-+http://mk.sg/7a&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://blog.mugunthkumar.com/coding/ios4-issue-nsurlconnection-and-nsoperation/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-googlereader">
			<a href="http://www.google.com/reader/link?url=http://blog.mugunthkumar.com/coding/ios4-issue-nsurlconnection-and-nsoperation/&amp;title=iOS4+Issue%3A+NSURLConnection+and+NSOperation&amp;srcUrl=http://blog.mugunthkumar.com/coding/ios4-issue-nsurlconnection-and-nsoperation/&amp;srcTitle=iOS4+Issue%3A+NSURLConnection+and+NSOperation&amp;snippet=Everyone%20knows%20NSOperation%20is%20easily%20the%20best%20way%20to%20automatically%20gain%20powerful%20multi-threading%20on%20iOS%2FMac%20platforms.%20However%2C%20recently%20for%20one%20of%20my%20apps%2C%20I%20faced%20a%20issue%20where%2C%20the%20NSURLConnection%27s%20initWithRequest%20method%20doesn%27t%20automatically%20start%20even%20if%20you%20forcefully%20send%20the%20%22start%22%20message" rel="nofollow" class="external" title="Add this to Google Reader">Add this to Google Reader</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://blog.mugunthkumar.com/coding/ios4-issue-nsurlconnection-and-nsoperation/&amp;title=iOS4+Issue%3A+NSURLConnection+and+NSOperation" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://blog.mugunthkumar.com/coding/ios4-issue-nsurlconnection-and-nsoperation/&amp;t=iOS4+Issue%3A+NSURLConnection+and+NSOperation" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-friendfeed">
			<a href="http://www.friendfeed.com/share?title=iOS4+Issue%3A+NSURLConnection+and+NSOperation&amp;link=http://blog.mugunthkumar.com/coding/ios4-issue-nsurlconnection-and-nsoperation/" rel="nofollow" class="external" title="Share this on FriendFeed">Share this on FriendFeed</a>
		</li>
		<li class="shr-gmail">
			<a href="https://mail.google.com/mail/?ui=2&amp;view=cm&amp;fs=1&amp;tf=1&amp;su=iOS4+Issue%3A+NSURLConnection+and+NSOperation&amp;body=Link: http://blog.mugunthkumar.com/coding/ios4-issue-nsurlconnection-and-nsoperation/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A Everyone%20knows%20NSOperation%20is%20easily%20the%20best%20way%20to%20automatically%20gain%20powerful%20multi-threading%20on%20iOS%2FMac%20platforms.%20However%2C%20recently%20for%20one%20of%20my%20apps%2C%20I%20faced%20a%20issue%20where%2C%20the%20NSURLConnection%27s%20initWithRequest%20method%20doesn%27t%20automatically%20start%20even%20if%20you%20forcefully%20send%20the%20%22start%22%20message" rel="nofollow" class="external" title="Email this via Gmail">Email this via Gmail</a>
		</li>
		<li class="shr-googlebookmarks">
			<a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://blog.mugunthkumar.com/coding/ios4-issue-nsurlconnection-and-nsoperation/&amp;title=iOS4+Issue%3A+NSURLConnection+and+NSOperation" rel="nofollow" class="external" title="Add this to Google Bookmarks">Add this to Google Bookmarks</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

<p>&copy;2010 <a href="http://blog.mugunthkumar.com">MK Blog</a>. All Rights Reserved.</p>.

<p>Related posts:<ol><li><a href='http://blog.mugunthkumar.com/coding/consuming-a-restful-service-bit-ly-in-an-iphone-application/' rel='bookmark' title='Permanent Link: Consuming a RESTful Service (bit.ly) in an iPhone Application'>Consuming a RESTful Service (bit.ly) in an iPhone Application</a> <small>bit-ly-rest-api-objective-c Introduction Of late, many programmers who develop for Windows/Linux...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.mugunthkumar.com/coding/ios4-issue-nsurlconnection-and-nsoperation/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>iPhone Tutorial: How to send In-App SMS</title>
		<link>http://blog.mugunthkumar.com/coding/iphone-tutorial-how-to-send-in-app-sms/</link>
		<comments>http://blog.mugunthkumar.com/coding/iphone-tutorial-how-to-send-in-app-sms/#comments</comments>
		<pubDate>Tue, 15 Jun 2010 10:37:39 +0000</pubDate>
		<dc:creator>Mugunth Kumar</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[objective c]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://blog.mugunthkumar.com/?p=769</guid>
		<description><![CDATA[Officially, iPhone OS 4 is out of NDA and I can&#8217;t write a post on this. If you have been reading my blogs, you might already know how to send a in-app email Sending a in-app SMS is very similar to this, but with subtle differences. Prior to iPhone OS 4, developers have to depend [...]


Related posts:<ol><li><a href='http://blog.mugunthkumar.com/coding/iphone-tutorial-elegant-way-to-send-formatted-in-app-email/' rel='bookmark' title='Permanent Link: iPhone Tutorial: Elegant way to send formatted In-App email'>iPhone Tutorial: Elegant way to send formatted In-App email</a> <small>By now, most of you know how to send emails...</small></li>
<li><a href='http://blog.mugunthkumar.com/coding/iphone-tutorial-enabling-reviewers-to-use-your-in-app-purchases-for-free/' rel='bookmark' title='Permanent Link: iPhone Tutorial &#8211; Enabling reviewers to use your In-App purchases for free'>iPhone Tutorial &#8211; Enabling reviewers to use your In-App purchases for free</a> <small>In-App purchases is a great way for developers to upsell...</small></li>
<li><a href='http://blog.mugunthkumar.com/coding/iphone-tutorial-uisearchdisplaycontroller-with-nspredicate/' rel='bookmark' title='Permanent Link: iPhone Tutorial &#8211; UISearchDisplayController with NSPredicate'>iPhone Tutorial &#8211; UISearchDisplayController with NSPredicate</a> <small>Though UISearchDisplayController is seemingly easy (and yes it&#8217;s easy), apart...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Officially, iPhone OS 4 is out of NDA and I can&#8217;t write a post on this. If you have been reading my blogs, you might already know how to send a <a href="http://blog.mugunthkumar.com/coding/iphone-tutorial-in-app-email/">in-app email</a> Sending a in-app SMS is very similar to this, but with subtle differences.</p>
<p>Prior to iPhone OS 4, developers have to depend on</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIApplication sharedApplication<span style="color: #002200;">&#93;</span> openURL<span style="color: #002200;">:</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;sms:12345678&quot;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>The problem with this is not just that it closes your app, but there is no way to specify the body content of the SMS. Secondly, you are restricted to send the SMS to only one person. However, with the new MessageUI SMS controller, you can send SMS to multiple people at the same time. You can also pre-populate the SMS body field.<br />
Developers of famous apps like Whatsapp Messenger, copy the SMS text content to clipboard and open the SMS app to allow users to paste the content. But with this newly allowed In-App SMS sheet, users can send SMS without quitting the app.</p>
<p>So, Let&#8217;s get started.</p>
<h3>Step 1:</h3>
<p>Import the MessageUI Framework into your project and #import the header file  into the &#8220;.h&#8221; file of your controller where you want to open the In-App SMS sheet.</p>
<h3>Step 2:</h3>
<p>You might already have a button handler IBAction where you want to send the SMS. If not create a Button on your XIB file and write IBActions for it.</p>
<h3>Step 3:</h3>
<p>The real 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>IBAction<span style="color: #002200;">&#41;</span> sendInAppSMS<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> sender
<span style="color: #002200;">&#123;</span>
	MFMessageComposeViewController <span style="color: #002200;">*</span>controller <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>MFMessageComposeViewController alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>MFMessageComposeViewController canSendText<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>
	<span style="color: #002200;">&#123;</span>
		controller.body <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Hello from Mugunth&quot;</span>;
		controller.recipients <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSArray</span> arrayWithObjects<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;12345678&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;87654321&quot;</span>, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
		controller.messageComposeDelegate <span style="color: #002200;">=</span> self;
		<span style="color: #002200;">&#91;</span>self presentModalViewController<span style="color: #002200;">:</span>controller animated<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>The most important part here is the line [MFMessageComposeViewController canSendText].<br />
When sending a in-app email, you can choose to ignore this (atleast as of now) because most of the devices would have upgraded to iPhone OS 3 and all those devices would have the ability to send in-app email. However, the same doesn&#8217;t apply to SMS. Remember that even if a device is running iPhone OS 4, if it&#8217;s an iPod touch, it will never be abel to send SMS within app.<br />
In this case, I have used a if condition to send the SMS. Practically speaking, you should enable/disable the button the user taps to send the sms based on this. You can add the code that does this in your viewDidLoad method.</p>
<p>Secondly, you have to set the messageComposeDelegate to self and not delegate. If you set the controller.delegate to self, you will not get the didFinishWithResult callback and the In-App SMS sheet will not close.</p>
<h3>Step 4:</h3>
<p>Implement Delegate Callbacks.<br />
In your header file, implement the callbacks, MFMessageComposeViewControllerDelegate and UINavigationControllerDelegate. If you don&#8217;t you will get a warning at the line,</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"> controller.delegate <span style="color: #002200;">=</span> self;</pre></div></div>

<p>You have to handle a callback method of MFMessageComposeViewControllerDelegate so as to dismiss the modal view controller.</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>messageComposeViewController<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>MFMessageComposeViewController <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>controller didFinishWithResult<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>MessageComposeResult<span style="color: #002200;">&#41;</span>result
<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">switch</span> <span style="color: #002200;">&#40;</span>result<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		<span style="color: #a61390;">case</span> MessageComposeResultCancelled<span style="color: #002200;">:</span>
			NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Cancelled&quot;</span><span style="color: #002200;">&#41;</span>;
			<span style="color: #a61390;">break</span>;
		<span style="color: #a61390;">case</span> MessageComposeResultFailed<span style="color: #002200;">:</span>
			UIAlertView <span style="color: #002200;">*</span>alert <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIAlertView alloc<span style="color: #002200;">&#93;</span> initWithTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;MyApp&quot;</span> message<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Unknown Error&quot;</span>
														   delegate<span style="color: #002200;">:</span>self cancelButtonTitle<span style="color: #002200;">:</span>@”OK” otherButtonTitles<span style="color: #002200;">:</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
			<span style="color: #002200;">&#91;</span>alert show<span style="color: #002200;">&#93;</span>;
			<span style="color: #002200;">&#91;</span>alert release<span style="color: #002200;">&#93;</span>;
			<span style="color: #a61390;">break</span>;
		<span style="color: #a61390;">case</span> MessageComposeResultSent<span style="color: #002200;">:</span>
&nbsp;
			<span style="color: #a61390;">break</span>;
		<span style="color: #a61390;">default</span><span style="color: #002200;">:</span>
			<span style="color: #a61390;">break</span>;
	<span style="color: #002200;">&#125;</span>
&nbsp;
	<span style="color: #002200;">&#91;</span>self dismissModalViewControllerAnimated<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>That&#8217;s it. Your app should now be able to send SMS using the new Message UI sheet.</p>
<h2></h2>
<h2>Where the heck is MMS in this tutorial?</h2>
<p>As on date, the MFMessageComposeViewController doesn&#8217;t support sending MMS. The controller.body is a NSString and setting a NSData pointer obviously crashes the app. Hopefully, one day, Apple will allow sending In-App MMS and I&#8217;ll probably blog about that too&#8230;</p>
<p><map name='google_ad_map_769_8b86e81420c6776e'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/769?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_769_8b86e81420c6776e' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=769&amp;url= http%3A%2F%2Fblog.mugunthkumar.com%2Fcoding%2Fiphone-tutorial-how-to-send-in-app-sms%2F' /></p>

<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-wealth">
<ul class="socials">
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=iPhone+Tutorial%3A+How+to+send+In-App+SMS+-+http://mk.sg/79&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://blog.mugunthkumar.com/coding/iphone-tutorial-how-to-send-in-app-sms/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-googlereader">
			<a href="http://www.google.com/reader/link?url=http://blog.mugunthkumar.com/coding/iphone-tutorial-how-to-send-in-app-sms/&amp;title=iPhone+Tutorial%3A+How+to+send+In-App+SMS&amp;srcUrl=http://blog.mugunthkumar.com/coding/iphone-tutorial-how-to-send-in-app-sms/&amp;srcTitle=iPhone+Tutorial%3A+How+to+send+In-App+SMS&amp;snippet=Officially%2C%20iPhone%20OS%204%20is%20out%20of%20NDA%20and%20I%20can%27t%20write%20a%20post%20on%20this.%20If%20you%20have%20been%20reading%20my%20blogs%2C%20you%20might%20already%20know%20how%20to%20send%20a%20in-app%20email%20Sending%20a%20in-app%20SMS%20is%20very%20similar%20to%20this%2C%20but%20with%20subtle%20differences.%0D%0A%0D%0APrior%20to%20iPhone%20OS%204%2C%20developers%20have%20to%20depend%20on%0D%0A%5B%5BUIApplicati" rel="nofollow" class="external" title="Add this to Google Reader">Add this to Google Reader</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://blog.mugunthkumar.com/coding/iphone-tutorial-how-to-send-in-app-sms/&amp;title=iPhone+Tutorial%3A+How+to+send+In-App+SMS" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://blog.mugunthkumar.com/coding/iphone-tutorial-how-to-send-in-app-sms/&amp;t=iPhone+Tutorial%3A+How+to+send+In-App+SMS" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-friendfeed">
			<a href="http://www.friendfeed.com/share?title=iPhone+Tutorial%3A+How+to+send+In-App+SMS&amp;link=http://blog.mugunthkumar.com/coding/iphone-tutorial-how-to-send-in-app-sms/" rel="nofollow" class="external" title="Share this on FriendFeed">Share this on FriendFeed</a>
		</li>
		<li class="shr-gmail">
			<a href="https://mail.google.com/mail/?ui=2&amp;view=cm&amp;fs=1&amp;tf=1&amp;su=iPhone+Tutorial%3A+How+to+send+In-App+SMS&amp;body=Link: http://blog.mugunthkumar.com/coding/iphone-tutorial-how-to-send-in-app-sms/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A Officially%2C%20iPhone%20OS%204%20is%20out%20of%20NDA%20and%20I%20can%27t%20write%20a%20post%20on%20this.%20If%20you%20have%20been%20reading%20my%20blogs%2C%20you%20might%20already%20know%20how%20to%20send%20a%20in-app%20email%20Sending%20a%20in-app%20SMS%20is%20very%20similar%20to%20this%2C%20but%20with%20subtle%20differences.%0D%0A%0D%0APrior%20to%20iPhone%20OS%204%2C%20developers%20have%20to%20depend%20on%0D%0A%5B%5BUIApplicati" rel="nofollow" class="external" title="Email this via Gmail">Email this via Gmail</a>
		</li>
		<li class="shr-googlebookmarks">
			<a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://blog.mugunthkumar.com/coding/iphone-tutorial-how-to-send-in-app-sms/&amp;title=iPhone+Tutorial%3A+How+to+send+In-App+SMS" rel="nofollow" class="external" title="Add this to Google Bookmarks">Add this to Google Bookmarks</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

<p>&copy;2010 <a href="http://blog.mugunthkumar.com">MK Blog</a>. All Rights Reserved.</p>.

<p>Related posts:<ol><li><a href='http://blog.mugunthkumar.com/coding/iphone-tutorial-elegant-way-to-send-formatted-in-app-email/' rel='bookmark' title='Permanent Link: iPhone Tutorial: Elegant way to send formatted In-App email'>iPhone Tutorial: Elegant way to send formatted In-App email</a> <small>By now, most of you know how to send emails...</small></li>
<li><a href='http://blog.mugunthkumar.com/coding/iphone-tutorial-enabling-reviewers-to-use-your-in-app-purchases-for-free/' rel='bookmark' title='Permanent Link: iPhone Tutorial &#8211; Enabling reviewers to use your In-App purchases for free'>iPhone Tutorial &#8211; Enabling reviewers to use your In-App purchases for free</a> <small>In-App purchases is a great way for developers to upsell...</small></li>
<li><a href='http://blog.mugunthkumar.com/coding/iphone-tutorial-uisearchdisplaycontroller-with-nspredicate/' rel='bookmark' title='Permanent Link: iPhone Tutorial &#8211; UISearchDisplayController with NSPredicate'>iPhone Tutorial &#8211; UISearchDisplayController with NSPredicate</a> <small>Though UISearchDisplayController is seemingly easy (and yes it&#8217;s easy), apart...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.mugunthkumar.com/coding/iphone-tutorial-how-to-send-in-app-sms/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>iPhone Tutorial: Elegant way to send formatted In-App email</title>
		<link>http://blog.mugunthkumar.com/coding/iphone-tutorial-elegant-way-to-send-formatted-in-app-email/</link>
		<comments>http://blog.mugunthkumar.com/coding/iphone-tutorial-elegant-way-to-send-formatted-in-app-email/#comments</comments>
		<pubDate>Sun, 07 Mar 2010 06:14:08 +0000</pubDate>
		<dc:creator>Mugunth Kumar</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[clean-code]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[iphone dev]]></category>
		<category><![CDATA[objective c]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://blog.mugunthkumar.com/?p=705</guid>
		<description><![CDATA[By now, most of you know how to send emails using the Message UI framework without quitting the app. In this tutorial, we will briefly discuss the techniques for sending a HTML formatted email with user generated content. Though sending a HTML formatted email is as easy as setting the option to HTML &#91;picker setMessageBody:emailBody [...]


Related posts:<ol><li><a href='http://blog.mugunthkumar.com/coding/iphone-tutorial-how-to-send-in-app-sms/' rel='bookmark' title='Permanent Link: iPhone Tutorial: How to send In-App SMS'>iPhone Tutorial: How to send In-App SMS</a> <small>Officially, iPhone OS 4 is out of NDA and I...</small></li>
<li><a href='http://blog.mugunthkumar.com/coding/iphone-tutorial-enabling-reviewers-to-use-your-in-app-purchases-for-free/' rel='bookmark' title='Permanent Link: iPhone Tutorial &#8211; Enabling reviewers to use your In-App purchases for free'>iPhone Tutorial &#8211; Enabling reviewers to use your In-App purchases for free</a> <small>In-App purchases is a great way for developers to upsell...</small></li>
<li><a href='http://blog.mugunthkumar.com/coding/iphone-tutorial-uisearchdisplaycontroller-with-nspredicate/' rel='bookmark' title='Permanent Link: iPhone Tutorial &#8211; UISearchDisplayController with NSPredicate'>iPhone Tutorial &#8211; UISearchDisplayController with NSPredicate</a> <small>Though UISearchDisplayController is seemingly easy (and yes it&#8217;s easy), apart...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>By now, most of you know <a href="http://blog.mugunthkumar.com/coding/iphone-tutorial-in-app-email/">how to send emails using the Message UI framework</a> without quitting the app. In  this tutorial, we will briefly discuss the techniques for sending a HTML formatted email with user generated content. Though sending a HTML formatted email is as easy as setting the option to HTML</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span>picker setMessageBody<span style="color: #002200;">:</span>emailBody isHTML<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>There are some cases that this method that this method doesn&#8217;t take care of. In short, this method works great for sending &#8220;Tell a friend about this app&#8221; email. But if your app needs much more sophistication, especially, if it needs to email data created by the user, you can follow the approach I suggest. Using this method, you can also adapt your code for International support and send the same email in multiple languages without any &#8220;<a href="http://en.wikipedia.org/wiki/Hard_coding">hard-coding</a>&#8221;</p>
<p>Though the method promises some great features, it is ridiculously simple. <img src='http://blog.mugunthkumar.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h2>Step 1:</h2>
<p>Create a HTML File with the contents of your email and add it to your project. You should <strong>NOT </strong>create any css or link it to any external CSS files. All your styles whether embedded withing the &lt;STYLE&gt; tag or kept as a separate CSS file will mostly be stripped by email clients. The reason could be because email clients don&#8217;t want your CSS to mess around with their client CSS. Read <a href="http://css-discuss.incutio.com/?page=StyleInEmail">this</a> article for more details. A sample is given below.</p>
<h2>Step 2:</h2>
<p>Insert placeholder markers within your HTML file. Your HTML file should look something like this.<br />
<code><br />
&lt;font size = '1' color= "#222222" style = "font-family: 'Lucida Grande', 'Lucida Sans Unicode', Helvetica, Arial;"&gt;&lt;i&gt;<strong>//TEXT_PLACEHOLDER//</strong>&lt;/i&gt;&lt;/font&gt;<br />
&lt;font size = '2' color= "#000000" style = "font-family: 'Lucida Grande', 'Lucida Sans Unicode', Helvetica, Arial;"&gt; Have a great day! &lt;br/&gt;<strong>//FRIENDNAME_PLACEHOLDER// </strong>&lt;br/&gt;&lt;/font&gt;<br />
</code><br />
The bold markers are the placeholders. You can assume them to be variables in the email. We will be replacing them later.</p>
<h2>Step 3:</h2>
<p>Do exactly the same steps for sending an in app email explained in one of my <a href="http://blog.mugunthkumar.com/coding/iphone-tutorial-in-app-email/"> previous tutorial</a>, but rather than hardcoding the email body like this,</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>emailBody <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;%@<span style="color: #2400d9;">\n</span><span style="color: #2400d9;">\n</span>
Sent from &lt;a href=&quot;</span><span style="color: #002200;">%</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&gt;MyGreatApp&lt;/a&gt; on iPhone. &lt;a href=&quot;</span><span style="color: #002200;">%</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&gt;Download&lt;/a&gt; yours from AppStore now!
&quot;</span>, content, pageLink, iTunesLink<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>Read it from your HTML File you created in Step 2.</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>langString <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>userDefaults dictionaryRepresentation<span style="color: #002200;">&#93;</span> objectForKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;NSLocaleCode&quot;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>emailFileName <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;email_%@.html&quot;</span>, langString<span style="color: #002200;">&#93;</span>;
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>emailFilePath <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</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> stringByAppendingPathComponent<span style="color: #002200;">:</span> emailFileName<span style="color: #002200;">&#93;</span>;
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>body <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithContentsOfFile<span style="color: #002200;">:</span>emailFilePath encoding<span style="color: #002200;">:</span>NSUTF8StringEncoding error<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>Note that, I&#8217;m appending the locale code with the email filename. That means you should create your email file by name email_en_US.html and similarly for other language files. </p>
<h2>Step 4:</h2>
<p>Replace placeholder texts with your contents generated within the app.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">body <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>body stringByReplacingOccurrencesOfString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;//TEXT_PLACEHOLDER//&quot;</span> withString<span style="color: #002200;">:</span>myText<span style="color: #002200;">&#93;</span>;
body <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>body stringByReplacingOccurrencesOfString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;//FRIENDNAME_PLACEHOLDER//&quot;</span> withString<span style="color: #002200;">:</span>myFriendName<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>The values myText and myFriendName should be passed to this email function.</p>
<p>With this architecture in place, you can format your email, change language and do a lot more without much changes to your code. After all, writing cleaner code is more important in the long run.</p>
<p>&#8211;<br />
Mugunth</p>
<p><map name='google_ad_map_705_8b86e81420c6776e'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/705?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_705_8b86e81420c6776e' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=705&amp;url= http%3A%2F%2Fblog.mugunthkumar.com%2Fcoding%2Fiphone-tutorial-elegant-way-to-send-formatted-in-app-email%2F' /></p>

<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-wealth">
<ul class="socials">
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=iPhone+Tutorial%3A+Elegant+way+to+send+formatted+In-App+email+-+http://mk.sg/6e&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://blog.mugunthkumar.com/coding/iphone-tutorial-elegant-way-to-send-formatted-in-app-email/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-googlereader">
			<a href="http://www.google.com/reader/link?url=http://blog.mugunthkumar.com/coding/iphone-tutorial-elegant-way-to-send-formatted-in-app-email/&amp;title=iPhone+Tutorial%3A+Elegant+way+to+send+formatted+In-App+email&amp;srcUrl=http://blog.mugunthkumar.com/coding/iphone-tutorial-elegant-way-to-send-formatted-in-app-email/&amp;srcTitle=iPhone+Tutorial%3A+Elegant+way+to+send+formatted+In-App+email&amp;snippet=By%20now%2C%20most%20of%20you%20know%20how%20to%20send%20emails%20using%20the%20Message%20UI%20framework%20without%20quitting%20the%20app.%20In%20%20this%20tutorial%2C%20we%20will%20briefly%20discuss%20the%20techniques%20for%20sending%20a%20HTML%20formatted%20email%20with%20user%20generated%20content.%20Though%20sending%20a%20HTML%20formatted%20email%20is%20as%20easy%20as%20setting%20the%20option%20to%20HTM" rel="nofollow" class="external" title="Add this to Google Reader">Add this to Google Reader</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://blog.mugunthkumar.com/coding/iphone-tutorial-elegant-way-to-send-formatted-in-app-email/&amp;title=iPhone+Tutorial%3A+Elegant+way+to+send+formatted+In-App+email" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://blog.mugunthkumar.com/coding/iphone-tutorial-elegant-way-to-send-formatted-in-app-email/&amp;t=iPhone+Tutorial%3A+Elegant+way+to+send+formatted+In-App+email" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-friendfeed">
			<a href="http://www.friendfeed.com/share?title=iPhone+Tutorial%3A+Elegant+way+to+send+formatted+In-App+email&amp;link=http://blog.mugunthkumar.com/coding/iphone-tutorial-elegant-way-to-send-formatted-in-app-email/" rel="nofollow" class="external" title="Share this on FriendFeed">Share this on FriendFeed</a>
		</li>
		<li class="shr-gmail">
			<a href="https://mail.google.com/mail/?ui=2&amp;view=cm&amp;fs=1&amp;tf=1&amp;su=iPhone+Tutorial%3A+Elegant+way+to+send+formatted+In-App+email&amp;body=Link: http://blog.mugunthkumar.com/coding/iphone-tutorial-elegant-way-to-send-formatted-in-app-email/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A By%20now%2C%20most%20of%20you%20know%20how%20to%20send%20emails%20using%20the%20Message%20UI%20framework%20without%20quitting%20the%20app.%20In%20%20this%20tutorial%2C%20we%20will%20briefly%20discuss%20the%20techniques%20for%20sending%20a%20HTML%20formatted%20email%20with%20user%20generated%20content.%20Though%20sending%20a%20HTML%20formatted%20email%20is%20as%20easy%20as%20setting%20the%20option%20to%20HTM" rel="nofollow" class="external" title="Email this via Gmail">Email this via Gmail</a>
		</li>
		<li class="shr-googlebookmarks">
			<a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://blog.mugunthkumar.com/coding/iphone-tutorial-elegant-way-to-send-formatted-in-app-email/&amp;title=iPhone+Tutorial%3A+Elegant+way+to+send+formatted+In-App+email" rel="nofollow" class="external" title="Add this to Google Bookmarks">Add this to Google Bookmarks</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

<p>&copy;2010 <a href="http://blog.mugunthkumar.com">MK Blog</a>. All Rights Reserved.</p>.

<p>Related posts:<ol><li><a href='http://blog.mugunthkumar.com/coding/iphone-tutorial-how-to-send-in-app-sms/' rel='bookmark' title='Permanent Link: iPhone Tutorial: How to send In-App SMS'>iPhone Tutorial: How to send In-App SMS</a> <small>Officially, iPhone OS 4 is out of NDA and I...</small></li>
<li><a href='http://blog.mugunthkumar.com/coding/iphone-tutorial-enabling-reviewers-to-use-your-in-app-purchases-for-free/' rel='bookmark' title='Permanent Link: iPhone Tutorial &#8211; Enabling reviewers to use your In-App purchases for free'>iPhone Tutorial &#8211; Enabling reviewers to use your In-App purchases for free</a> <small>In-App purchases is a great way for developers to upsell...</small></li>
<li><a href='http://blog.mugunthkumar.com/coding/iphone-tutorial-uisearchdisplaycontroller-with-nspredicate/' rel='bookmark' title='Permanent Link: iPhone Tutorial &#8211; UISearchDisplayController with NSPredicate'>iPhone Tutorial &#8211; UISearchDisplayController with NSPredicate</a> <small>Though UISearchDisplayController is seemingly easy (and yes it&#8217;s easy), apart...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.mugunthkumar.com/coding/iphone-tutorial-elegant-way-to-send-formatted-in-app-email/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Tutorial: Follow Cost API and a open source wrapper</title>
		<link>http://blog.mugunthkumar.com/coding/iphone-tutorial-follow-cost-api-and-a-open-source-wrapper/</link>
		<comments>http://blog.mugunthkumar.com/coding/iphone-tutorial-follow-cost-api-and-a-open-source-wrapper/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 15:31:45 +0000</pubDate>
		<dc:creator>Mugunth Kumar</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[iphone dev]]></category>
		<category><![CDATA[objective c]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://blog.mugunthkumar.com/?p=669</guid>
		<description><![CDATA[What is Follow Cost? Follow Cost is a interesting and powerful statistic that helps you check the &#8220;cost&#8221; you would incur by &#8220;following&#8221; a person on twitter. This is a very useful statistic that I think every twitter client should adopt.  Tweetie for iPhone was the first to implement follow cost and I use this [...]


Related posts:<ol><li><a href='http://blog.mugunthkumar.com/coding/consuming-a-restful-service-bit-ly-in-an-iphone-application/' rel='bookmark' title='Permanent Link: Consuming a RESTful Service (bit.ly) in an iPhone Application'>Consuming a RESTful Service (bit.ly) in an iPhone Application</a> <small>bit-ly-rest-api-objective-c Introduction Of late, many programmers who develop for Windows/Linux...</small></li>
<li><a href='http://blog.mugunthkumar.com/coding/bit-ly-wrapper-objective-c-iphone/' rel='bookmark' title='Permanent Link: bit.ly wrapper for Objective-C/iPhone'>bit.ly wrapper for Objective-C/iPhone</a> <small>Continuing from my part 1, in this section, we will...</small></li>
<li><a href='http://blog.mugunthkumar.com/coding/iphone-tutorial-enabling-reviewers-to-use-your-in-app-purchases-for-free/' rel='bookmark' title='Permanent Link: iPhone Tutorial &#8211; Enabling reviewers to use your In-App purchases for free'>iPhone Tutorial &#8211; Enabling reviewers to use your In-App purchases for free</a> <small>In-App purchases is a great way for developers to upsell...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<h2>What is Follow Cost?</h2>
<p><a href="http://followcost.com">Follow Cost</a> is a interesting and powerful statistic that helps you check the &#8220;cost&#8221; you would incur by &#8220;following&#8221; a person on twitter. This is a very useful statistic that I think every twitter client should adopt.  <a href="http://www.atebits.com/tweetie-iphone">Tweetie for iPhone</a> was the first to implement follow cost and I use this feature of tweetie to check whether a follower is &#8220;worth the pain&#8221; (as follow cost puts it).</p>
<p>In short, Follow Cost gives you an approximate count of the number of updates a person tweets in a day. As a thumb rule, I don&#8217;t follow anyone with a follow cost of over 40. A celebrity with a high follow cost is <a href="http://twitter.com/guykawasaki">@guykawasaki</a>. (80+ at the time of this writing) His tweets are interesting, but is it worth the pain? Depends. To me, definitely not.</p>
<h2>The API</h2>
<p>Follow Cost has a <a href="http://followcost.com/about/api">relatively simple API</a>. But unfortunately, even after 3 months of Tweetie 2 launch, no other twitter client has implemented. You just have to make a GET request to followcost.com server with the twitter username as follows.<code>=<br />
</code></p>
<blockquote><p>http://followcost.com/<em><strong>&lt;username&gt;</strong></em>.json</p></blockquote>
<p>The resulting output is a json formatted string which can be parsed using any <a href="http://code.google.com/p/json-framework/">JSON Framework</a>.</p>
<h2>Objective C Code</h2>
<p>To make life easier, I wrote a helper class MKFollowCost. To use the class, first download the JSON framework and follow their <a href="http://code.google.com/p/json-framework/wiki/InstallationInstructions">installation instructions</a>. If you are writing a twitter client, chances are that, you would probably have done this. Download the code from below and drag the two files, MKFollowCost.h and MKFollowCost.m into your project.</p>
<p>You can instantiate a followcost object by<br />
<code>MKFollowCost *followCost = [[MKFollowCost alloc] initWithTwitterName:@"mugunthkumar"];</code><br />
All of the variables like, milliscobles, tweets per day etc, can be accessed from this object. The object is designed to be embedded without your Twitter Profile object.</p>
<h2>Downloads</h2>
<p>FollowCost Objective C Wrapper: <a href="http://blog.mugunthkumar.com/wp-content/uploads/FollowCost-v1.0.zip">FollowCost v1.0</a></p>
<h3>Rights</h3>
<p>You can use it in your own Twitter client, royalty free. Attributing me is upto you. However, if you modify the source code, please make it open source.</p>
<p><map name='google_ad_map_669_8b86e81420c6776e'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/669?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_669_8b86e81420c6776e' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=669&amp;url= http%3A%2F%2Fblog.mugunthkumar.com%2Fcoding%2Fiphone-tutorial-follow-cost-api-and-a-open-source-wrapper%2F' /></p>

<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-wealth">
<ul class="socials">
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=iPhone+Tutorial%3A+Follow+Cost+API+and+a+open+source+wrapper+-+http://mk.sg/4j&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://blog.mugunthkumar.com/coding/iphone-tutorial-follow-cost-api-and-a-open-source-wrapper/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-googlereader">
			<a href="http://www.google.com/reader/link?url=http://blog.mugunthkumar.com/coding/iphone-tutorial-follow-cost-api-and-a-open-source-wrapper/&amp;title=iPhone+Tutorial%3A+Follow+Cost+API+and+a+open+source+wrapper&amp;srcUrl=http://blog.mugunthkumar.com/coding/iphone-tutorial-follow-cost-api-and-a-open-source-wrapper/&amp;srcTitle=iPhone+Tutorial%3A+Follow+Cost+API+and+a+open+source+wrapper&amp;snippet=What%20is%20Follow%20Cost%3F%0D%0AFollow%20Cost%20is%20a%20interesting%20and%20powerful%20statistic%20that%20helps%20you%20check%20the%20%22cost%22%20you%20would%20incur%20by%20%22following%22%20a%20person%20on%20twitter.%20This%20is%20a%20very%20useful%20statistic%20that%20I%20think%20every%20twitter%20client%20should%20adopt.%C2%A0%20Tweetie%20for%20iPhone%20was%20the%20first%20to%20implement%20follow%20cost%20an" rel="nofollow" class="external" title="Add this to Google Reader">Add this to Google Reader</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://blog.mugunthkumar.com/coding/iphone-tutorial-follow-cost-api-and-a-open-source-wrapper/&amp;title=iPhone+Tutorial%3A+Follow+Cost+API+and+a+open+source+wrapper" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://blog.mugunthkumar.com/coding/iphone-tutorial-follow-cost-api-and-a-open-source-wrapper/&amp;t=iPhone+Tutorial%3A+Follow+Cost+API+and+a+open+source+wrapper" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-friendfeed">
			<a href="http://www.friendfeed.com/share?title=iPhone+Tutorial%3A+Follow+Cost+API+and+a+open+source+wrapper&amp;link=http://blog.mugunthkumar.com/coding/iphone-tutorial-follow-cost-api-and-a-open-source-wrapper/" rel="nofollow" class="external" title="Share this on FriendFeed">Share this on FriendFeed</a>
		</li>
		<li class="shr-gmail">
			<a href="https://mail.google.com/mail/?ui=2&amp;view=cm&amp;fs=1&amp;tf=1&amp;su=iPhone+Tutorial%3A+Follow+Cost+API+and+a+open+source+wrapper&amp;body=Link: http://blog.mugunthkumar.com/coding/iphone-tutorial-follow-cost-api-and-a-open-source-wrapper/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A What%20is%20Follow%20Cost%3F%0D%0AFollow%20Cost%20is%20a%20interesting%20and%20powerful%20statistic%20that%20helps%20you%20check%20the%20%22cost%22%20you%20would%20incur%20by%20%22following%22%20a%20person%20on%20twitter.%20This%20is%20a%20very%20useful%20statistic%20that%20I%20think%20every%20twitter%20client%20should%20adopt.%C2%A0%20Tweetie%20for%20iPhone%20was%20the%20first%20to%20implement%20follow%20cost%20an" rel="nofollow" class="external" title="Email this via Gmail">Email this via Gmail</a>
		</li>
		<li class="shr-googlebookmarks">
			<a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://blog.mugunthkumar.com/coding/iphone-tutorial-follow-cost-api-and-a-open-source-wrapper/&amp;title=iPhone+Tutorial%3A+Follow+Cost+API+and+a+open+source+wrapper" rel="nofollow" class="external" title="Add this to Google Bookmarks">Add this to Google Bookmarks</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

<p>&copy;2010 <a href="http://blog.mugunthkumar.com">MK Blog</a>. All Rights Reserved.</p>.

<p>Related posts:<ol><li><a href='http://blog.mugunthkumar.com/coding/consuming-a-restful-service-bit-ly-in-an-iphone-application/' rel='bookmark' title='Permanent Link: Consuming a RESTful Service (bit.ly) in an iPhone Application'>Consuming a RESTful Service (bit.ly) in an iPhone Application</a> <small>bit-ly-rest-api-objective-c Introduction Of late, many programmers who develop for Windows/Linux...</small></li>
<li><a href='http://blog.mugunthkumar.com/coding/bit-ly-wrapper-objective-c-iphone/' rel='bookmark' title='Permanent Link: bit.ly wrapper for Objective-C/iPhone'>bit.ly wrapper for Objective-C/iPhone</a> <small>Continuing from my part 1, in this section, we will...</small></li>
<li><a href='http://blog.mugunthkumar.com/coding/iphone-tutorial-enabling-reviewers-to-use-your-in-app-purchases-for-free/' rel='bookmark' title='Permanent Link: iPhone Tutorial &#8211; Enabling reviewers to use your In-App purchases for free'>iPhone Tutorial &#8211; Enabling reviewers to use your In-App purchases for free</a> <small>In-App purchases is a great way for developers to upsell...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.mugunthkumar.com/coding/iphone-tutorial-follow-cost-api-and-a-open-source-wrapper/feed/</wfw:commentRss>
		<slash:comments>38</slash:comments>
		</item>
		<item>
		<title>iPhone Tutorial &#8211; Enabling reviewers to use your In-App purchases for free</title>
		<link>http://blog.mugunthkumar.com/coding/iphone-tutorial-enabling-reviewers-to-use-your-in-app-purchases-for-free/</link>
		<comments>http://blog.mugunthkumar.com/coding/iphone-tutorial-enabling-reviewers-to-use-your-in-app-purchases-for-free/#comments</comments>
		<pubDate>Sun, 15 Nov 2009 15:48:29 +0000</pubDate>
		<dc:creator>Mugunth Kumar</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[iphone dev]]></category>
		<category><![CDATA[objective c]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://blog.mugunthkumar.com/?p=559</guid>
		<description><![CDATA[In-App purchases is a great way for developers to upsell by giving away their app for free and then allow them to charge for features when users start using it. This freemium model has indeed worked very well for upselling your app in the AppStore. But unfortunately, there isn&#8217;t an Apple allowed way to allow [...]


Related posts:<ol><li><a href='http://blog.mugunthkumar.com/coding/iphone-tutorial-%e2%80%93-in-app-purchases/' rel='bookmark' title='Permanent Link: iPhone Tutorial – In-App Purchases'>iPhone Tutorial – In-App Purchases</a> <small>Last week, Apple announced that in-app purchases will be available...</small></li>
<li><a href='http://blog.mugunthkumar.com/coding/iphone-tutorial-uisearchdisplaycontroller-with-nspredicate/' rel='bookmark' title='Permanent Link: iPhone Tutorial &#8211; UISearchDisplayController with NSPredicate'>iPhone Tutorial &#8211; UISearchDisplayController with NSPredicate</a> <small>Though UISearchDisplayController is seemingly easy (and yes it&#8217;s easy), apart...</small></li>
<li><a href='http://blog.mugunthkumar.com/coding/iphone-tutorial-follow-cost-api-and-a-open-source-wrapper/' rel='bookmark' title='Permanent Link: iPhone Tutorial: Follow Cost API and a open source wrapper'>iPhone Tutorial: Follow Cost API and a open source wrapper</a> <small>What is Follow Cost? Follow Cost is a interesting and...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>In-App purchases is a great way for developers to upsell by giving away their app for free and then allow them to charge for features when users start using it. This freemium model has indeed worked very well for upselling your app in the AppStore. But unfortunately, there isn&#8217;t an Apple allowed way to allow reviewers to &#8220;download&#8221; your in-app purchases for free (like giving away promotional codes for your in-app purchases). So most developers again resort to the same &#8220;lite&#8221;, &#8220;pro&#8221; model.</p>
<p>After raising the issue to Apple, I even got a official reply that it&#8217;s not possible currently to allow reviewers to use your in-app purchases for free.</p>
<p><a href="http://blog.mugunthkumar.com/wp-content/uploads/noinappurchases.png"><img class="aligncenter size-medium wp-image-566" title="noinappurchases" src="http://blog.mugunthkumar.com/wp-content/uploads/noinappurchases-300x132.png" alt="noinappurchases" width="300" height="132" /></a></p>
<p>However, developers&#8217; creativity knows no bounds. In this post, I&#8217;ll present a method to allow reviewers to use your in-app purchases for free without having multiple versions of the same app on the app store. The source code for the same is also available royalty-free (as always) for using it in your own apps. Before diving in, it&#8217;s advised that you read through my previous <a href="http://blog.mugunthkumar.com/coding/iphone-tutorial-–-in-app-purchases">tutorial on how to do in-app purchases</a></p>
<p><span id="more-559"></span></p>
<h2>Focus</h2>
<p>As I previously wrote, you can sell consumables, non-consumables and subscriptions using the in-app purchases model. This article is focussed primarily on consumables and non-consumables. However, you can extend it to subscriptions as well by adding a bit more server side PHP programming. This post however focusses on adding this feature to consumable and non-consumable items only.</p>
<h2>A Quick Recap</h2>
<p>By now, you must be knowing the flow of a in-app purchase request. If you don&#8217;t, read through my in-app purchases tutorial. As a recap,</p>
<p>1) You list the items available for sale from your store to the user.</p>
<p>2) When the user chooses a feature, you prepare a SKPayment object and add it to the queue.</p>
<p>3) Listen to notifications and record the purchases within your apps&#8217; NSUserDefaults.</p>
<p>Or it&#8217;s even more simple if you had used my MKStoreKit.</p>
<h2>The Idea</h2>
<p>The idea here is to maintain a list of device IDs on the developer server and check whether the current device is exempted to use the feature without purchasing. If the device is allowed, rather than initiating a purchase, temporarily set the variables as if the transactions were made.</p>
<p>The complete source code,  MKStoreKit V2.0 is attached at the end of the post.</p>
<p>You should be glad to know that, you don&#8217;t have to make changes to your calling code to add this feature.<br />
In MKStoreKit, there is a function called buyFeature which initiates a in-app purchase request. In version 2.0, this function is modified to make a check first to your server (server code is also attached to this post) passing the UDID of the current device. If your server responds with a YES, it activates the feature temporarily without &#8220;actually purchasing&#8221;. This will enable your reviewers to review your app without buying your in-app purchase.</p>
<p>- (BOOL) canCurrentDeviceUseFeature: (NSString*) featureID;</p>
<p>This is the function that is called. Currently it checks the server mentioned in the variable ownServer (presently set to nil). To enable this function, you have to do the server side changes as explained in the next step.</p>
<h2>Server Side Changes</h2>
<p>Setup a database with two tables setup in your server. One table for storing a list of available products and another for storing new review requests as they come in.</p>
<p>The products table has the following fields<br />
<em><strong>productid    productName    productDesc</strong></em></p>
<p>The requests table has the following fields<br />
<em><strong>udid    productid    email    message    status    lastUpdated</strong></em></p>
<p>You can use the SQL file attached to create these tables. Add a user to your MySql database and fill in the user id and password into the two php files.</p>
<p>Copy the server files from the ServerCode folder to some location like</p>
<p>http://api.mycompany.com/inapp/</p>
<p>change the &#8220;ownServer&#8221; variable in MKStoreManager.m to </p>
<p>http://api.mycompany.com/inapp/featureCheck.php</p>
<p>The featureCheck.php file checks the requests table for the UDID and the featureID. If the status of that row is 1, it returns YES. If your server returns YES for a particular UDID, the app activates the purchase for the current session without initiating a StoreKit purchase. Note that, this featureCheck happens everytime the app is started. Hence, if you deactivate a UDID on your server after the reviewer has finished reviewing, he will not be able to continue using it for free (Which means, you have actually given the reviewer a sneak-peek to your feature. Even if he likes it, he has to buy it)</p>
<h2>How to send your review request?</h2>
<p>There are atleast three ways of doing this.<br />
One way is to ask your reviewers to send the UDID to you by email. You can ask them to use the <a href="http://itunes.apple.com/us/app/ad-hoc-helper/id285691333?mt=8">Ad Hoc Helper by Erica Sadun</a> You can then manually add it into the database using the AddDevice.html (present in the Server Code folder)<br />
Second way is,  You can &#8220;pretty up&#8221; the AddDevice.html and host it somewhere in your server. Send a link to this to your reviewers for filling their UDID/Product ID.<br />
Third, as in my case, I&#8217;ve created a separate iPhone App for doing this. The only reason for doing so is, filling the UDID is very very cumbersome and error prone. If anyone knows a way to read the UDID of a device from a webapp, do let me know. (The big5 code didn&#8217;t work for me)</p>
<h2>Going forward</h2>
<p>I understand that all this server side setup is quite cumbersome. The server code isn&#8217;t even polished like the MKStoreKit. If Apple approves this method (which I will know in another 20 days), In MKStoreKit 3.0, I&#8217;ll probably throw of the whole server side code and replace it with a much elegant method by using a Google Spreadsheet. I haven&#8217;t yet digged around with the <a href="http://code.google.com/apis/spreadsheets/">spreadsheets API</a>. This way, you can implement the same feature without even owning a server <img src='http://blog.mugunthkumar.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p>I might as well add in features to migrate your existing customers who use your pro version to the version with in-app purchases. Stay tuned!</p>
<h2>Source Code (Much awaited)</h2>
<p><a href="http://blog.mugunthkumar.com/wp-content/uploads/MKStoreKit-V2.0.zip">MKStoreKit V2.0</a><br />
If you cannot successfully use this, you can hire me to do it for you. <img src='http://blog.mugunthkumar.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  I usually freelance through <a href="http://www.odesk.com/community/user/10015207">oDesk.com</a></p>
<p><map name='google_ad_map_559_8b86e81420c6776e'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/559?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_559_8b86e81420c6776e' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=559&amp;url= http%3A%2F%2Fblog.mugunthkumar.com%2Fcoding%2Fiphone-tutorial-enabling-reviewers-to-use-your-in-app-purchases-for-free%2F' /></p>

<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-wealth">
<ul class="socials">
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=iPhone+Tutorial+-+Enabling+reviewers+to+use+your+In-App+purchases+for+free+-+http://mk.sg/31&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://blog.mugunthkumar.com/coding/iphone-tutorial-enabling-reviewers-to-use-your-in-app-purchases-for-free/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-googlereader">
			<a href="http://www.google.com/reader/link?url=http://blog.mugunthkumar.com/coding/iphone-tutorial-enabling-reviewers-to-use-your-in-app-purchases-for-free/&amp;title=iPhone+Tutorial+-+Enabling+reviewers+to+use+your+In-App+purchases+for+free&amp;srcUrl=http://blog.mugunthkumar.com/coding/iphone-tutorial-enabling-reviewers-to-use-your-in-app-purchases-for-free/&amp;srcTitle=iPhone+Tutorial+-+Enabling+reviewers+to+use+your+In-App+purchases+for+free&amp;snippet=In-App%20purchases%20is%20a%20great%20way%20for%20developers%20to%20upsell%20by%20giving%20away%20their%20app%20for%20free%20and%20then%20allow%20them%20to%20charge%20for%20features%20when%20users%20start%20using%20it.%20This%20freemium%20model%20has%20indeed%20worked%20very%20well%20for%20upselling%20your%20app%20in%20the%20AppStore.%20But%20unfortunately%2C%20there%20isn%27t%20an%20Apple%20allowed%20way" rel="nofollow" class="external" title="Add this to Google Reader">Add this to Google Reader</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://blog.mugunthkumar.com/coding/iphone-tutorial-enabling-reviewers-to-use-your-in-app-purchases-for-free/&amp;title=iPhone+Tutorial+-+Enabling+reviewers+to+use+your+In-App+purchases+for+free" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://blog.mugunthkumar.com/coding/iphone-tutorial-enabling-reviewers-to-use-your-in-app-purchases-for-free/&amp;t=iPhone+Tutorial+-+Enabling+reviewers+to+use+your+In-App+purchases+for+free" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-friendfeed">
			<a href="http://www.friendfeed.com/share?title=iPhone+Tutorial+-+Enabling+reviewers+to+use+your+In-App+purchases+for+free&amp;link=http://blog.mugunthkumar.com/coding/iphone-tutorial-enabling-reviewers-to-use-your-in-app-purchases-for-free/" rel="nofollow" class="external" title="Share this on FriendFeed">Share this on FriendFeed</a>
		</li>
		<li class="shr-gmail">
			<a href="https://mail.google.com/mail/?ui=2&amp;view=cm&amp;fs=1&amp;tf=1&amp;su=iPhone+Tutorial+-+Enabling+reviewers+to+use+your+In-App+purchases+for+free&amp;body=Link: http://blog.mugunthkumar.com/coding/iphone-tutorial-enabling-reviewers-to-use-your-in-app-purchases-for-free/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A In-App%20purchases%20is%20a%20great%20way%20for%20developers%20to%20upsell%20by%20giving%20away%20their%20app%20for%20free%20and%20then%20allow%20them%20to%20charge%20for%20features%20when%20users%20start%20using%20it.%20This%20freemium%20model%20has%20indeed%20worked%20very%20well%20for%20upselling%20your%20app%20in%20the%20AppStore.%20But%20unfortunately%2C%20there%20isn%27t%20an%20Apple%20allowed%20way" rel="nofollow" class="external" title="Email this via Gmail">Email this via Gmail</a>
		</li>
		<li class="shr-googlebookmarks">
			<a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://blog.mugunthkumar.com/coding/iphone-tutorial-enabling-reviewers-to-use-your-in-app-purchases-for-free/&amp;title=iPhone+Tutorial+-+Enabling+reviewers+to+use+your+In-App+purchases+for+free" rel="nofollow" class="external" title="Add this to Google Bookmarks">Add this to Google Bookmarks</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

<p>&copy;2010 <a href="http://blog.mugunthkumar.com">MK Blog</a>. All Rights Reserved.</p>.

<p>Related posts:<ol><li><a href='http://blog.mugunthkumar.com/coding/iphone-tutorial-%e2%80%93-in-app-purchases/' rel='bookmark' title='Permanent Link: iPhone Tutorial – In-App Purchases'>iPhone Tutorial – In-App Purchases</a> <small>Last week, Apple announced that in-app purchases will be available...</small></li>
<li><a href='http://blog.mugunthkumar.com/coding/iphone-tutorial-uisearchdisplaycontroller-with-nspredicate/' rel='bookmark' title='Permanent Link: iPhone Tutorial &#8211; UISearchDisplayController with NSPredicate'>iPhone Tutorial &#8211; UISearchDisplayController with NSPredicate</a> <small>Though UISearchDisplayController is seemingly easy (and yes it&#8217;s easy), apart...</small></li>
<li><a href='http://blog.mugunthkumar.com/coding/iphone-tutorial-follow-cost-api-and-a-open-source-wrapper/' rel='bookmark' title='Permanent Link: iPhone Tutorial: Follow Cost API and a open source wrapper'>iPhone Tutorial: Follow Cost API and a open source wrapper</a> <small>What is Follow Cost? Follow Cost is a interesting and...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.mugunthkumar.com/coding/iphone-tutorial-enabling-reviewers-to-use-your-in-app-purchases-for-free/feed/</wfw:commentRss>
		<slash:comments>53</slash:comments>
		</item>
		<item>
		<title>iPhone Tutorial &#8211; UISearchDisplayController with NSPredicate</title>
		<link>http://blog.mugunthkumar.com/coding/iphone-tutorial-uisearchdisplaycontroller-with-nspredicate/</link>
		<comments>http://blog.mugunthkumar.com/coding/iphone-tutorial-uisearchdisplaycontroller-with-nspredicate/#comments</comments>
		<pubDate>Sun, 15 Nov 2009 04:37:46 +0000</pubDate>
		<dc:creator>Mugunth Kumar</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[iphone dev]]></category>
		<category><![CDATA[objective c]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[UISearchDisplayController]]></category>

		<guid isPermaLink="false">http://blog.mugunthkumar.com/?p=549</guid>
		<description><![CDATA[Though UISearchDisplayController is seemingly easy (and yes it&#8217;s easy), apart from the sample source code, there isn&#8217;t much documentation available from Apple. I won&#8217;t be posting code for this tutorial, (as most of them come from Apple&#8217;s own source code), however, the tutorial will contain code fragments that I wish to highlight and those I [...]


Related posts:<ol><li><a href='http://blog.mugunthkumar.com/coding/iphone-tutorial-enabling-reviewers-to-use-your-in-app-purchases-for-free/' rel='bookmark' title='Permanent Link: iPhone Tutorial &#8211; Enabling reviewers to use your In-App purchases for free'>iPhone Tutorial &#8211; Enabling reviewers to use your In-App purchases for free</a> <small>In-App purchases is a great way for developers to upsell...</small></li>
<li><a href='http://blog.mugunthkumar.com/coding/iphone-tutorial-%e2%80%93-in-app-purchases/' rel='bookmark' title='Permanent Link: iPhone Tutorial – In-App Purchases'>iPhone Tutorial – In-App Purchases</a> <small>Last week, Apple announced that in-app purchases will be available...</small></li>
<li><a href='http://blog.mugunthkumar.com/coding/iphone-tutorial-follow-cost-api-and-a-open-source-wrapper/' rel='bookmark' title='Permanent Link: iPhone Tutorial: Follow Cost API and a open source wrapper'>iPhone Tutorial: Follow Cost API and a open source wrapper</a> <small>What is Follow Cost? Follow Cost is a interesting and...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Though UISearchDisplayController is seemingly easy (and yes it&#8217;s easy), apart from the <a href="https://developer.apple.com/iphone/library/samplecode/TableSearch/">sample source code</a>, there isn&#8217;t much documentation available from Apple. I won&#8217;t be posting code for this tutorial, (as most of them come from Apple&#8217;s own source code), however, the tutorial will contain code fragments that I wish to highlight and those I changed for improving the search using <a href="http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Predicates/Articles/pCreating.html">NSPredicate</a><br />
<span id="more-549"></span></p>
<h2>Step 1: Create the project</h2>
<p>If you haven&#8217;t created a project yet, create a Navigation Based Project and open the RootViewController.xib.</p>
<h2>Step 2: Modify the XIB</h2>
<p>Drag UISearchDisplayController to your RootViewController.xib. (It automatically does the connections for you) Drag the SearchBar that gets added onto your TableView. You need the UISearchBar to be displayed on the controller. So drag the searchbar and place it on the top of the table view. Add ScopeBars if you need any. We will discuss later how to handle the scope bar changes and how to filter text based on the selected scope.</p>
<h2>Step 3: The Design of UISearchDisplayController</h2>
<p>In a traditional tableviewcontroller, you normally have one master list of data which you use for all the tableview data source methods. In case of UISearchDisplayController, you have to maintain two lists. One master list and one a filtered list. The tableview data source delegates will be called by the framework when it needs to populate your tableview or the search results. So in all the methods you have to differentiate whether the data source call is for populating the filtered list or for populating the main list.</p>
<p>This is done by a simple two line code.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>tableView <span style="color: #002200;">==</span> self.tableView<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
<span style="color: #11740a; font-style: italic;">// normal table view population</span>
<span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>tableView <span style="color: #002200;">==</span> self.searchDisplayController.searchResultsTableView<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
<span style="color: #11740a; font-style: italic;">// search view population</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>This code should be written in cellForRowAtIndexPath, didSelectRowAtIndexPath and numberOfRowsInSection.<br />
For the complete code listing, see Apple&#8217;s sample code.</p>
<h2>Step 3: Implement the search delegates</h2>
<p>When the user invokes a search,the UISearchDisplayDelegate functions you implement will be called. The two main functions that you have to implement are,</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>searchDisplayController<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UISearchDisplayController <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>controller 
shouldReloadTableForSearchScope<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>NSInteger<span style="color: #002200;">&#41;</span>searchOption
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>searchDisplayController<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UISearchDisplayController <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>controller 
shouldReloadTableForSearchString<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>searchString</pre></div></div>

<p>Copy the implementation from Apple&#8217;s source.In the header file, your class should implement UISearchBarDelegate and UISearchDisplayDelegate.</p>
<p>As the name suggests, the first function will be called when the user changes the scope button and the second function is called when he starts typing a search query. The first function is not necessary if you haven&#8217;t added any scope button in step 2.</p>
<h2>Step 4: Filtering your data using NSPredicate</h2>
<p>This step is the reason why I wrote this seemingly simple post. I didn&#8217;t like the Apple&#8217;s way of filtering. It doesn&#8217;t match &#8220;contains&#8221; text. I modified the <code>filterContentForSearchText </code>method, so as to use NSPredicate. You still need the Apple&#8217;s implementation of shouldReloadTableForSearchString and shouldReloadTableForSearchScope.<br />
The filterContentForSearchText implementation CANNOT be copy-pasted into your application. It&#8217;s a code fragment that doesn&#8217;t compile without some changes. Points to note in the function is the use of predicate.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #400080;">NSPredicate</span> <span style="color: #002200;">*</span>predicate <span style="color: #002200;">=</span> 
<span style="color: #002200;">&#91;</span><span style="color: #400080;">NSPredicate</span> predicateWithFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;(SELF contains[cd] %@)&quot;</span>, searchText<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>The [cd] in the predicate format means case and diatric insensitive. the verb I have used is &#8220;contains&#8221;, you can change it to beginsWith, endsWith, like and many others. The NSPredicate is a very powerful feature that can be exploited here. I don&#8217;t understand why Apple just didn&#8217;t use it <img src='http://blog.mugunthkumar.com/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' />  For more info, look at Apple&#8217;s NSPredicate documentation <a href="http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Predicates/Articles/pCreating.html">here</a></p>
<p>Below is the complete code listing after making the NSPredicate changes.</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>filterContentForSearchText<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>searchText scope<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>scope
<span style="color: #002200;">&#123;</span>
    <span style="color: #002200;">&#91;</span>self.filteredData removeAllObjects<span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">// First clear the filtered array.</span>
    <span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span>Product <span style="color: #002200;">*</span>product <span style="color: #a61390;">in</span> tableData<span style="color: #002200;">&#41;</span>
    <span style="color: #002200;">&#123;</span>
        <span style="color: #400080;">NSPredicate</span> <span style="color: #002200;">*</span>predicate <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSPredicate</span> predicateWithFormat<span style="color: #002200;">:</span>
           <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;(SELF contains[cd] %@)&quot;</span>, searchText<span style="color: #002200;">&#93;</span>;
       <span style="color: #002200;">&#91;</span>product.productID compare<span style="color: #002200;">:</span>searchText options<span style="color: #002200;">:</span>NSCaseInsensitiveSearch<span style="color: #002200;">&#93;</span>;
        <span style="color: #a61390;">BOOL</span> resultID <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>predicate evaluateWithObject<span style="color: #002200;">:</span>product.productID<span style="color: #002200;">&#93;</span>;
        <span style="color: #a61390;">BOOL</span> resultName <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>predicate evaluateWithObject<span style="color: #002200;">:</span>product.productName<span style="color: #002200;">&#93;</span>;
       <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>scope isEqualToString<span style="color: #002200;">:</span>@<span style="color: #002200;">&amp;</span>quot;Product ID<span style="color: #002200;">&amp;</span>quot;<span style="color: #002200;">&#93;</span> <span style="color: #002200;">&amp;&amp;</span> resultID<span style="color: #002200;">&#41;</span>
        <span style="color: #002200;">&#123;</span>
            <span style="color: #002200;">&#91;</span>self.filteredData addObject<span style="color: #002200;">:</span>product<span style="color: #002200;">&#93;</span>;
        <span style="color: #002200;">&#125;</span>
        <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>scope isEqualToString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Product Name&quot;</span><span style="color: #002200;">&#93;</span> <span style="color: #002200;">&amp;&amp;</span> resultName<span style="color: #002200;">&#41;</span>
        <span style="color: #002200;">&#123;</span>
            <span style="color: #002200;">&#91;</span>self.filteredData addObject<span style="color: #002200;">:</span>product<span style="color: #002200;">&#93;</span>;
        <span style="color: #002200;">&#125;</span>
        <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>scope isEqualToString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Any&quot;</span><span style="color: #002200;">&#93;</span> <span style="color: #002200;">&amp;&amp;</span> <span style="color: #002200;">&#40;</span>resultID || resultName<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>
        <span style="color: #002200;">&#123;</span>
            <span style="color: #002200;">&#91;</span>self.filteredData addObject<span style="color: #002200;">:</span>product<span style="color: #002200;">&#93;</span>;
        <span style="color: #002200;">&#125;</span>
    <span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>With NSPredicate, you can play around with the search filters. NSPredicate is as powerful and easier to use than Regular Expressions. Try your hand at it.</p>
<p>&#8211;<br />
Mugunth</p>
<p><map name='google_ad_map_549_8b86e81420c6776e'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/549?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_549_8b86e81420c6776e' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=549&amp;url= http%3A%2F%2Fblog.mugunthkumar.com%2Fcoding%2Fiphone-tutorial-uisearchdisplaycontroller-with-nspredicate%2F' /></p>

<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-wealth">
<ul class="socials">
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=iPhone+Tutorial+-+UISearchDisplayController+with+NSPredicate+-+http://mk.sg/30&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://blog.mugunthkumar.com/coding/iphone-tutorial-uisearchdisplaycontroller-with-nspredicate/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-googlereader">
			<a href="http://www.google.com/reader/link?url=http://blog.mugunthkumar.com/coding/iphone-tutorial-uisearchdisplaycontroller-with-nspredicate/&amp;title=iPhone+Tutorial+-+UISearchDisplayController+with+NSPredicate&amp;srcUrl=http://blog.mugunthkumar.com/coding/iphone-tutorial-uisearchdisplaycontroller-with-nspredicate/&amp;srcTitle=iPhone+Tutorial+-+UISearchDisplayController+with+NSPredicate&amp;snippet=Though%20UISearchDisplayController%20is%20seemingly%20easy%20%28and%20yes%20it%27s%20easy%29%2C%20apart%20from%20the%20sample%20source%20code%2C%20there%20isn%27t%20much%20documentation%20available%20from%20Apple.%20I%20won%27t%20be%20posting%20code%20for%20this%20tutorial%2C%20%28as%20most%20of%20them%20come%20from%20Apple%27s%20own%20source%20code%29%2C%20however%2C%20the%20tutorial%20will%20contain%20code%20frag" rel="nofollow" class="external" title="Add this to Google Reader">Add this to Google Reader</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://blog.mugunthkumar.com/coding/iphone-tutorial-uisearchdisplaycontroller-with-nspredicate/&amp;title=iPhone+Tutorial+-+UISearchDisplayController+with+NSPredicate" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://blog.mugunthkumar.com/coding/iphone-tutorial-uisearchdisplaycontroller-with-nspredicate/&amp;t=iPhone+Tutorial+-+UISearchDisplayController+with+NSPredicate" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-friendfeed">
			<a href="http://www.friendfeed.com/share?title=iPhone+Tutorial+-+UISearchDisplayController+with+NSPredicate&amp;link=http://blog.mugunthkumar.com/coding/iphone-tutorial-uisearchdisplaycontroller-with-nspredicate/" rel="nofollow" class="external" title="Share this on FriendFeed">Share this on FriendFeed</a>
		</li>
		<li class="shr-gmail">
			<a href="https://mail.google.com/mail/?ui=2&amp;view=cm&amp;fs=1&amp;tf=1&amp;su=iPhone+Tutorial+-+UISearchDisplayController+with+NSPredicate&amp;body=Link: http://blog.mugunthkumar.com/coding/iphone-tutorial-uisearchdisplaycontroller-with-nspredicate/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A Though%20UISearchDisplayController%20is%20seemingly%20easy%20%28and%20yes%20it%27s%20easy%29%2C%20apart%20from%20the%20sample%20source%20code%2C%20there%20isn%27t%20much%20documentation%20available%20from%20Apple.%20I%20won%27t%20be%20posting%20code%20for%20this%20tutorial%2C%20%28as%20most%20of%20them%20come%20from%20Apple%27s%20own%20source%20code%29%2C%20however%2C%20the%20tutorial%20will%20contain%20code%20frag" rel="nofollow" class="external" title="Email this via Gmail">Email this via Gmail</a>
		</li>
		<li class="shr-googlebookmarks">
			<a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://blog.mugunthkumar.com/coding/iphone-tutorial-uisearchdisplaycontroller-with-nspredicate/&amp;title=iPhone+Tutorial+-+UISearchDisplayController+with+NSPredicate" rel="nofollow" class="external" title="Add this to Google Bookmarks">Add this to Google Bookmarks</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

<p>&copy;2010 <a href="http://blog.mugunthkumar.com">MK Blog</a>. All Rights Reserved.</p>.

<p>Related posts:<ol><li><a href='http://blog.mugunthkumar.com/coding/iphone-tutorial-enabling-reviewers-to-use-your-in-app-purchases-for-free/' rel='bookmark' title='Permanent Link: iPhone Tutorial &#8211; Enabling reviewers to use your In-App purchases for free'>iPhone Tutorial &#8211; Enabling reviewers to use your In-App purchases for free</a> <small>In-App purchases is a great way for developers to upsell...</small></li>
<li><a href='http://blog.mugunthkumar.com/coding/iphone-tutorial-%e2%80%93-in-app-purchases/' rel='bookmark' title='Permanent Link: iPhone Tutorial – In-App Purchases'>iPhone Tutorial – In-App Purchases</a> <small>Last week, Apple announced that in-app purchases will be available...</small></li>
<li><a href='http://blog.mugunthkumar.com/coding/iphone-tutorial-follow-cost-api-and-a-open-source-wrapper/' rel='bookmark' title='Permanent Link: iPhone Tutorial: Follow Cost API and a open source wrapper'>iPhone Tutorial: Follow Cost API and a open source wrapper</a> <small>What is Follow Cost? Follow Cost is a interesting and...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.mugunthkumar.com/coding/iphone-tutorial-uisearchdisplaycontroller-with-nspredicate/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>iPhone Tutorial – In-App Purchases</title>
		<link>http://blog.mugunthkumar.com/coding/iphone-tutorial-%e2%80%93-in-app-purchases/</link>
		<comments>http://blog.mugunthkumar.com/coding/iphone-tutorial-%e2%80%93-in-app-purchases/#comments</comments>
		<pubDate>Sat, 17 Oct 2009 17:37:29 +0000</pubDate>
		<dc:creator>Mugunth Kumar</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[iphone dev]]></category>
		<category><![CDATA[objective c]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://blog.mugunthkumar.com/?p=518</guid>
		<description><![CDATA[Last week, Apple announced that in-app purchases will be available for free apps as well. This could probably free developers from creating &#8220;lite&#8221; and &#8220;pro&#8221; versions of the app and allow developers to &#8220;unlock&#8221; features inside the app and create business models that the AppStore haven&#8217;t seen. This model could be a great boon for [...]


Related posts:<ol><li><a href='http://blog.mugunthkumar.com/coding/iphone-tutorial-enabling-reviewers-to-use-your-in-app-purchases-for-free/' rel='bookmark' title='Permanent Link: iPhone Tutorial &#8211; Enabling reviewers to use your In-App purchases for free'>iPhone Tutorial &#8211; Enabling reviewers to use your In-App purchases for free</a> <small>In-App purchases is a great way for developers to upsell...</small></li>
<li><a href='http://blog.mugunthkumar.com/coding/iphone-tutorial-uisearchdisplaycontroller-with-nspredicate/' rel='bookmark' title='Permanent Link: iPhone Tutorial &#8211; UISearchDisplayController with NSPredicate'>iPhone Tutorial &#8211; UISearchDisplayController with NSPredicate</a> <small>Though UISearchDisplayController is seemingly easy (and yes it&#8217;s easy), apart...</small></li>
<li><a href='http://blog.mugunthkumar.com/coding/iphone-tutorial-follow-cost-api-and-a-open-source-wrapper/' rel='bookmark' title='Permanent Link: iPhone Tutorial: Follow Cost API and a open source wrapper'>iPhone Tutorial: Follow Cost API and a open source wrapper</a> <small>What is Follow Cost? Follow Cost is a interesting and...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Last week, Apple announced that in-app purchases will be available for free apps as well. This could probably free developers from creating &#8220;lite&#8221; and &#8220;pro&#8221; versions of the app and allow developers to &#8220;unlock&#8221; features inside the app and create business models that the AppStore haven&#8217;t seen. This model could be a great boon for developers like us to upsell our apps (provided they are of good quality) and to reduce piracy. In this article, we will look at how to incorporate StoreKit to do In-App purchases for your iPhone Application.</p>
<p><em>Update: Did it really free you from creating &#8220;lite&#8221; and &#8220;pro&#8221; versions? How did you manage to give away free copies of your in-app purchases for reviewers? Read my tutorial on how to<a href="http://blog.mugunthkumar.com/coding/iphone-tutorial-enabling-reviewers-to-use-your-in-app-purchases-for-free">enable in-app purchases for free</a></em></p>
<p>Apple allows three types of purchases within the app and Apple terms them as consumables, non-consumables and subscriptions.</p>
<p><strong>Consumables</strong> are products that are &#8220;consumed&#8221; immediately. This means, if the purchase is made today, and the user wants to purchase it again tomorrow, he will be charged again when he attempts a purchase.</p>
<p><strong>Non-Consumables</strong> are features that are purchased exactly once. Apple automatically takes care of &#8220;remembering&#8221; those purchases and allows the user to purchase them again for free, just like downloading apps you already purchased.</p>
<p><strong>Subscriptions</strong> are the most complicated part, They behave like non-consumables during the subscribed period and like consumables after that. You as a developer have to ensure that anything that is subscribed by the user is available across all of his iTunes synced devices when they are purchased from one device. Hence, do not lock in-app purchases to UDIDs. This might even get your app rejected. The StoreKit, as on date, doesn&#8217;t have any built-in mechanism to do it automatically which is why subscriptions are a bit tougher to develop.</p>
<p>One important point to note is that, in-app purchases cannot be used to deliver product updates. Changes to the binary has to be separately submitted. However, if you are a game developer, game data, maps, levels and other &#8220;data files&#8221; are allowed for in-app purchase.</p>
<p>In this post, we will focus on how to prepare your app for enabling features for the &#8220;pro&#8221; version from the &#8220;lite&#8221;. Or technically, we will focus on how to bring in, consumables and non-consumables into your app. We will leave the subscriptions part to another blog post as it&#8217;s quite complicated and involves some server side programming as well.<span id="more-518"></span></p>
<h2>Preparing your iTunes Connect</h2>
<p>To start with, in-app purchases, you need to do some ground work on your iTunes Connect account. A three step process that Apple thinks every developer should know. (Unfortunately I couldn&#8217;t find any official documentation for this)</p>
<h3>Step 1:</h3>
<p>First is to create an App ID and enable in-app purchases for that. This App ID shouldn&#8217;t have any wild card characters or else, the in-app purchases option will be grayed. I would always recommend to use a different App ID for every application you create. </p>
<h3 style="font-size: 1.17em;">Step 2:</h3>
<p>Create provisioning profiles (Development and Distribution) using this App ID. Again it&#8217;s a good practice to create different provisioning profiles for every app. There are many tutorials on how to create this <a href="http://www.wikihow.com/Create-a-Provisioning-Profile-for-iPhone">here</a> and Apple&#8217;s own documentation <a href="http://adcdownload.apple.com/iphone/iphone_developer_program_user_guide/iphone_developer_program_user_guide__standard_program_v2.4.pdf">here</a> (This link will prompt you to login).</p>
<h3 style="font-size: 1.17em;">Step 3:</h3>
<p>You need to create product references in your iTunes account. Each individual in-app purchase should be uniquely identifiable. Apple recommends using the <a href="http://en.wikipedia.org/wiki/Reverse-DNS">reverse DNS notation</a>, something like, com.mycompany.myiproduct.ifeature Before creating product ids, you need to associate it with a existing application in AppStore. If your app is not yet live, you can create a dummy, placeholder application, fill in the metadata (which you can anyway change it later) and check &#8220;upload binary later&#8221;.</p>
<p>To create a new in-app purchase, open your <a href="https://itunesconnect.apple.com">itunes connect</a> and choose &#8220;Manage In-App purchases&#8221;. Choose the app for which you want to setup in-app purchases and click next. You should see a screen like this.</p>
<p><a href="http://blog.mugunthkumar.com/wp-content/uploads/iTunes-Connect-1.png"><img class="aligncenter size-medium wp-image-522" title="iTunes Connect in-app Purchase" src="http://blog.mugunthkumar.com/wp-content/uploads/iTunes-Connect-1-300x103.png" alt="iTunes Connect in-app Purchase" width="300" height="103" /></a></p>
<p>The reference name is the name that appears during the in-app purchase prompt. Any name like, Levels 10 &#8211; 50 will be fine. The Product ID should be unique. This is used for reporting as well as within your app for requesting a purchase (more on this later). You can select the type as consumable or non-consumable. When you say an in-app purchase is consumable, your users will be charged everytime they purchase it. This is perfect for a radio app that requires users to pay for listening to a song everytime. If it&#8217;s a product feature, set it as non-consumable. Non-consumable products are purchased exactly once. When the user attempts to purchase it again, it will be delivered to him for free.</p>
<p>Type in the other required detail in this page and click save.</p>
<h3 style="font-size: 1.17em;">Step 4:</h3>
<p>The fourth and final step is to create test user accounts. After you program the app, you might want to test the app. You can use these accounts to login to the App Store. The purchases will be processed as if it were real but no financial transactions will take place.</p>
<p>This completes your iTunes connect configuration. Take a deep breath. We have just started. A lot more to go.</p>
<h2 style="font-size: 1.5em;">Writing the StoreKit Code</h2>
<p>Now that you have setup the iTunes account, let&#8217;s start by writing the actual code to interact with the AppStore and allow users to make purchases. For coding help, nothing beats the <a href="http://developer.apple.com/iphone/library/documentation/NetworkingInternet/Conceptual/StoreKitGuide/AddingaStoretoYourApplication/AddingaStoretoYourApplication.html#//apple_ref/doc/uid/TP40008267-CH101-SW1">Apple&#8217;s official StoreKit programming guide</a>. However, the guide has one bug that crashes the program. We will see how to circumvent it properly here.</p>
<h3 style="font-size: 1.17em;">Step 1: Adding StoreKit.Framework</h3>
<p>The first step here is to add the StoreKit.Framework to your project.</p>
<h3 style="font-size: 1.17em;">Step 2: Parental Controls</h3>
<p>It&#8217;s important to check whether the iPhone/iPod doesn&#8217;t have parental control restrictions. When you try to initiate a purchase when parental controls are on, you might crash your app. The apple docs code seems to have an error here. The function, canMakePayments is a static method of class SKPaymentQueue and not a member function. The working code looks like this.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>SKPaymentQueue canMakePayments<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>
<span style="color: #002200;">&#123;</span>
... <span style="color: #11740a; font-style: italic;">// Display a store to the user.</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;">// Warn the user that purchases are disabled.</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<h3 style="font-size: 1.17em;">Step 3: Retrieving the product information and populating the UI</h3>
<p>Now the you have designed a gorgeous looking view, you can show it to the user using, say presentmodalviewcontroller or any similar method. Do note that StoreKit doesn&#8217;t provide the UI to be displayed. It&#8217;s upto the developer to design the UI. The first step is to query your &#8220;In-App Purchases&#8221; and show the user, the available list of options. Retrieving the product information from AppStore is a couple of lines of code as illustrated here.</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> requestProductData
<span style="color: #002200;">&#123;</span>
SKProductsRequest <span style="color: #002200;">*</span>request<span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>SKProductsRequest alloc<span style="color: #002200;">&#93;</span> 
initWithProductIdentifiers<span style="color: #002200;">:</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSSet</span> setWithObject<span style="color: #002200;">:</span> kMyFeatureIdentifier<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
request.delegate <span style="color: #002200;">=</span> self;
<span style="color: #002200;">&#91;</span>request start<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>productsRequest<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>SKProductsRequest <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>request didReceiveResponse<span style="color: #002200;">:</span>
        <span style="color: #002200;">&#40;</span>SKProductsResponse <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>response
<span style="color: #002200;">&#123;</span>
<span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>myProduct <span style="color: #002200;">=</span> response.products;
<span style="color: #11740a; font-style: italic;">// populate UI</span>
<span style="color: #002200;">&#91;</span>request autorelease<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>The <em>kMyFeatureIdentifier</em> you pass to initWithProductIdentifiers is the uniquely identifiable product id you created in your AppStore account. Remember the reverse DNS product id? You CANNOT specify a wild card character here. So, if you have multiple products, you have to initialize the request object with a list of product using</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">SKProductsRequest <span style="color: #002200;">*</span>request<span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>SKProductsRequest alloc<span style="color: #002200;">&#93;</span> 
initWithProductIdentifiers<span style="color: #002200;">:</span>
<span style="color: #002200;">&#91;</span><span style="color: #400080;">NSSet</span> setWithObjects<span style="color: #002200;">:</span> myGreatFeature1, myGreatFeature2, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>You can pass as many features as possible to setWithObjects and be sure to end the last object with nil.<br />
Setting the delegate to self and calling the start method will invoke the &#8220;didReceiveResponse&#8221; delegate. The delegate will give you an array of products and the request itself. Use the array to populate your store UI and release your request here. (This is the same request you created initially).</p>
<h3 style="font-size: 1.17em;">Step 4: Adding a Transaction Observer</h3>
<p>This is a very important step. You can do this as soon as your app is open or when you start a &#8220;In-App&#8221; purchase session. Do note that, in-app purchase requests are continued even if the user quits the app in between. So imagine a case, when user buys an item, but before the transaction is processed, he gets a phone call that interrupts everything. Though the actual transaction is not interfered (as it happens on Apple servers), your application will never know what happened. To ensure that you get all transaction notifications, (completed/ pending/restored), you have to register a class that receives the callbacks from AppStore. This class should implement  and it&#8217;s delegate methods.<br />
This is the code for registering the your store observer.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">MKStoreObserver <span style="color: #002200;">*</span>observer <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>MKStoreObserver alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>SKPaymentQueue defaultQueue<span style="color: #002200;">&#93;</span> addTransactionObserver<span style="color: #002200;">:</span>observer<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>(If you can&#8217;t follow anything here, just head below for the real source code, but it&#8217;s advised that you read through this, understand and then use the code in your app).</p>
<h3 style="font-size: 1.17em;">Step 4: Implementing the callback</h3>
<p>Within your MKStoreObserver class, you have to implement the callback function paymentQueue:updatedTransactions:</p>
<p>This function will receive updates on the transactions as and when it&#8217;s made. Because your transactions take place even when the app is closed, you should be ready to receive these notifications as soon as you open the app. So the best place is to initialize it in applicationDidFinishLaunching or equivalent method.</p>
<p>Now in the updatedTransactions functions, handle the three types of transactions, purchased, failed and restored.</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>paymentQueue<span style="color: #002200;">:</span>updatedTransactions<span style="color: #002200;">&#40;</span>SKPaymentQueue <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>queue 
updatedTransactions<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>transactions
<span style="color: #002200;">&#123;</span>
<span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span>SKPaymentTransaction <span style="color: #002200;">*</span>transaction <span style="color: #a61390;">in</span> transactions<span style="color: #002200;">&#41;</span>
<span style="color: #002200;">&#123;</span>
<span style="color: #a61390;">switch</span> <span style="color: #002200;">&#40;</span>transaction.transactionState<span style="color: #002200;">&#41;</span>
<span style="color: #002200;">&#123;</span>
<span style="color: #a61390;">case</span> SKPaymentTransactionStatePurchased<span style="color: #002200;">:</span>
<span style="color: #11740a; font-style: italic;">// take action to purchase the feature</span>
<span style="color: #002200;">&#91;</span>self provideContent<span style="color: #002200;">:</span> transaction.payment.productIdentifier<span style="color: #002200;">&#93;</span>;
<span style="color: #a61390;">break</span>;
<span style="color: #a61390;">case</span> SKPaymentTransactionStateFailed<span style="color: #002200;">:</span>
<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>transaction.error.code <span style="color: #002200;">!=</span> SKErrorPaymentCancelled<span style="color: #002200;">&#41;</span>
<span style="color: #002200;">&#123;</span>
<span style="color: #11740a; font-style: italic;">// Optionally, display an error here.</span>
<span style="color: #002200;">&#125;</span>
<span style="color: #11740a; font-style: italic;">// take action to display some error message</span>
<span style="color: #a61390;">break</span>;
<span style="color: #a61390;">case</span> SKPaymentTransactionStateRestored<span style="color: #002200;">:</span>
<span style="color: #11740a; font-style: italic;">// take action to restore the app as if it was purchased</span>
<span style="color: #002200;">&#91;</span>self provideContent<span style="color: #002200;">:</span> transaction.originalTransaction.payment.productIdentifier<span style="color: #002200;">&#93;</span>;
<span style="color: #a61390;">default</span><span style="color: #002200;">:</span>
<span style="color: #a61390;">break</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #11740a; font-style: italic;">// Remove the transaction from the payment queue.</span>
<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>SKPaymentQueue defaultQueue<span style="color: #002200;">&#93;</span> finishTransaction<span style="color: #002200;">:</span> transaction<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>Purchase and failed are seemingly straightforward. You will receive a restored transaction message when your app was quit before the transaction was completed. You should always do the &#8220;same&#8221; thing when your purchase is new or restored. If you want to charge your users for every download, then probably, set the in-app purchase to be a &#8220;consumable&#8221; item. But be sure to use that only for purchases that are really &#8220;consumable&#8221;. Like a live radio show or a podcast and not for unlocking additional levels. Users expect that a level they have unlocked will stay forever.</p>
<p>Three things to note here<br />
1) You should remove the transaction from the payment queue after the transaction is complete. Otherwise, the transaction will be re-attempted, which is not what the users expect (and your app will most likely get rejected).</p>
<p>2) You should provide the content (or unlock the feature) before completing the transaction. When you receive the message SKPaymentTransactionStatePurchased, it means that the users&#8217; credit card has been charged. It&#8217;s high time that you provide the feature.</p>
<p>3) You should not display an error when the transaction fails because the user rejected it.  Display any error message only when,</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>transaction.error.code <span style="color: #002200;">!=</span> SKErrorPaymentCancelled<span style="color: #002200;">&#41;</span>&lt;<span style="color: #002200;">/</span>code&gt;</pre></div></div>

<p>Apple recommends you not to display an error, because that is not an error. The user has purposely cancelled the transaction (probably because the price was too high?). You can audit it and go on. But for heaven sake, don&#8217;t display an error like, &#8220;Unable to process transaction because user cancelled operation!&#8221;. It will be soooo Windozy&#8230;</p>
<h3 style="font-size: 1.17em;">Step 5: The actual purchase</h3>
<p>Now that your architecture is ready, you can go ahead and initiate the purchase by calling the function below when the user clicks your &#8220;Buy&#8221; button on the UI.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">SKPayment <span style="color: #002200;">*</span>payment <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>SKPayment paymentWithProductIdentifier<span style="color: #002200;">:</span>myGreatFeature1<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>SKPaymentQueue defaultQueue<span style="color: #002200;">&#93;</span> addPayment<span style="color: #002200;">:</span>payment<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>Optionally, you can add something like payment quantity for &#8220;consumable&#8221; items.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">payment.quantity <span style="color: #002200;">=</span> n; <span style="color: #11740a; font-style: italic;">// number of &quot;items&quot; that user wishes to purchase.</span></pre></div></div>

<p>Finally, after providing the feature, you should &#8220;remember&#8221; that the user has purchased the app. Apple&#8217;s recommended way is to use NSUserDefaults, the same way you store your settings.</p>
<h2 style="font-size: 1.5em;">Testing your app</h2>
<p>Alright. Now let&#8217;s test the app. Note that, the app cannot be testing from iPhone simulator. The StoreKit communicates with AppStore.app to complete transactions which is not present in the Simulator. So connect your iPhone and run the app.<br />
Remember step 3 you did in iTunes connect? You created some test accounts? Well, they are used for testing your app. Before using that, sign out of AppStore by opening Settings.app -&gt; Store -&gt; Sign Out.<br />
Start the app. (You should NOT sign into the AppStore with the test user account. It will anyway ask you to provide your credit card which we are not interested in)</p>
<p>Open the Store UI and initiate the purchase. You will get a prompt like, &#8220;Do you want to buy 1 &#8220;ABC feature&#8221; for 2.99$? Tap Buy. You will be prompted to login. Provide your test account login. The AppStore provides a secure connection to the iTunes account and notifies you whether the purchase was successful through the callback paymentQueue:updatedTransactions. When you use the test account, the scenarios will be exactly same expect that no one will be charged. These test accounts run inside a sandbox.</p>
<p>In case your app got quit by a phone call, the transactions continue and you will get a restoreTransactions the next time your app is opened. This is why you should start listening to transactions as soon as you open the app (not just when the user opens the store UI)</p>
<p>That&#8217;s it. I wouldn&#8217;t say its easy. But for developers who have some intermediate knowledge in iPhone development and Objective C, it shouldn&#8217;t be a big deal. Remember that when your app is free, you get 10 times more downloads (as reported by admob statistics). When people actually use your app, there is a high chance that they buy your in-app features. That&#8217;s upselling becomes easy. Given that this is a very strong business model for the already saturated AppStore, you should start incorporating this model into your code soon.</p>
<h2 style="font-size: 1.5em;">Source code</h2>
<p>The source code, MKStoreKit, contains four files. MKStoreManager.h/m and MKStoreObserver.h/m. The StoreManager is a singleton class that takes care of *everything* Include StoreKit framework into your product and drag these four files into the project. You then have to initialize it by calling [MKStoreManager sharedStorageManager] in your applicationDidFinishLaunching. From then on, it does the magic. The MKStoreKit automatically activates/deactivates features based on your userDefaults. When a feature is purchased, it automatically records it into NSUserDefaults. For checking whether the user has purchased the feature, you can call a function like,</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>MKStoreManager featureAPurchased<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>
<span style="color: #002200;">&#123;</span>
<span style="color: #11740a; font-style: italic;">//unlock it</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>To purchase a feature, just call</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>MKStoreManager sharedManager<span style="color: #002200;">&#93;</span> buyFeatureA<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>It&#8217;s that simple with my storekit. The source code will be uploaded when this post is read by at least 1000 people. Please spread the word.</p>
<p>As always, all my source code can be used without royalty into your app. Just make sure that you don&#8217;t remove the copyright notice from the source code if you make your app open source. You don&#8217;t have to attribute me in your app, although I would be glad if you do so <img src='http://blog.mugunthkumar.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Downloads:<br />
Version 2:<a href="http://blog.mugunthkumar.com/wp-content/uploads/MKStoreKit-V2.0.zip">MKStoreKit V2.0</a><br />
Version 1:<a href="http://blog.mugunthkumar.com/wp-content/uploads/MKStoreKit.zip">MKStoreKit.zip</a></p>
<h2 style="font-size: 1.5em;">Troubleshooting</h2>
<p>Despite all this, In-App Purchases remain a biggest and the most <a href="http://www.netlingo.com/word/pita.php">PITA </a>situation for any iPhone developer.  If you can&#8217;t get it work, check whether your &#8220;didReceiveResponse&#8221; delegate returns the product id you passed as invalid. You can confirm this by adding a NSLog statement inside the delegate. Double check if your invalid product id returned here matches the product id you created in iTunes connect. If they are same, check if your product id on iTunes connect says &#8220;Cleared for Sale&#8221;. For this, you have to provide a screenshot and &#8220;Developer Approve&#8221; it.</p>
<p>Another case is, if this is your first app, then chances are that, your &#8220;Paid Applications Contract&#8221; isn&#8217;t yet in effect. If this is the case, you have to wait till Apple approves your bank details.</p>
<p>If these two doesn&#8217;t work, you might have to wait for 12-24 hrs, till Apple propagates your iTunes connect information to all it&#8217;s servers. See the last line in <a href="http://developer.apple.com/iphone/library/documentation/NetworkingInternet/Conceptual/StoreKitGuide/RetrievingStoreInformation/RetrievingStoreInformation.html#//apple_ref/doc/uid/TP40008267-CH2-SW1">this</a> documentation for more details.</p>
<p>If you have issues adding this to your application, you can hire me to do it for you. I charge a nominal fee of 150$ &#8211; 200$ (depending on the complexity) for the whole integration. You can also approach me for a customized code that suits your business model as well.</p>
<p><strong>Update 1: (22-Oct-2009): Code changes to fix a crash that occured in most cases.</strong><br />
<strong>Update 2: (7-Dec-2009): Added link to MKStoreKit v2.0.</strong><br />
&#8211;<br />
Mugunth</p>
<p><map name='google_ad_map_518_8b86e81420c6776e'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/518?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_518_8b86e81420c6776e' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=518&amp;url= http%3A%2F%2Fblog.mugunthkumar.com%2Fcoding%2Fiphone-tutorial-%25e2%2580%2593-in-app-purchases%2F' /></p>

<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-wealth">
<ul class="socials">
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=iPhone+Tutorial+%E2%80%93+In-App+Purchases+-+http://mk.sg/1m&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://blog.mugunthkumar.com/coding/iphone-tutorial-%e2%80%93-in-app-purchases/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-googlereader">
			<a href="http://www.google.com/reader/link?url=http://blog.mugunthkumar.com/coding/iphone-tutorial-%e2%80%93-in-app-purchases/&amp;title=iPhone+Tutorial+%E2%80%93+In-App+Purchases&amp;srcUrl=http://blog.mugunthkumar.com/coding/iphone-tutorial-%e2%80%93-in-app-purchases/&amp;srcTitle=iPhone+Tutorial+%E2%80%93+In-App+Purchases&amp;snippet=Last%20week%2C%20Apple%20announced%20that%20in-app%20purchases%20will%20be%20available%20for%20free%20apps%20as%20well.%20This%20could%20probably%20free%20developers%20from%20creating%20%22lite%22%20and%20%22pro%22%20versions%20of%20the%20app%20and%20allow%20developers%20to%20%22unlock%22%20features%20inside%20the%20app%20and%20create%20business%20models%20that%20the%20AppStore%20haven%27t%20seen.%20This%20mo" rel="nofollow" class="external" title="Add this to Google Reader">Add this to Google Reader</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://blog.mugunthkumar.com/coding/iphone-tutorial-%e2%80%93-in-app-purchases/&amp;title=iPhone+Tutorial+%E2%80%93+In-App+Purchases" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://blog.mugunthkumar.com/coding/iphone-tutorial-%e2%80%93-in-app-purchases/&amp;t=iPhone+Tutorial+%E2%80%93+In-App+Purchases" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-friendfeed">
			<a href="http://www.friendfeed.com/share?title=iPhone+Tutorial+%E2%80%93+In-App+Purchases&amp;link=http://blog.mugunthkumar.com/coding/iphone-tutorial-%e2%80%93-in-app-purchases/" rel="nofollow" class="external" title="Share this on FriendFeed">Share this on FriendFeed</a>
		</li>
		<li class="shr-gmail">
			<a href="https://mail.google.com/mail/?ui=2&amp;view=cm&amp;fs=1&amp;tf=1&amp;su=iPhone+Tutorial+%E2%80%93+In-App+Purchases&amp;body=Link: http://blog.mugunthkumar.com/coding/iphone-tutorial-%e2%80%93-in-app-purchases/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A Last%20week%2C%20Apple%20announced%20that%20in-app%20purchases%20will%20be%20available%20for%20free%20apps%20as%20well.%20This%20could%20probably%20free%20developers%20from%20creating%20%22lite%22%20and%20%22pro%22%20versions%20of%20the%20app%20and%20allow%20developers%20to%20%22unlock%22%20features%20inside%20the%20app%20and%20create%20business%20models%20that%20the%20AppStore%20haven%27t%20seen.%20This%20mo" rel="nofollow" class="external" title="Email this via Gmail">Email this via Gmail</a>
		</li>
		<li class="shr-googlebookmarks">
			<a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://blog.mugunthkumar.com/coding/iphone-tutorial-%e2%80%93-in-app-purchases/&amp;title=iPhone+Tutorial+%E2%80%93+In-App+Purchases" rel="nofollow" class="external" title="Add this to Google Bookmarks">Add this to Google Bookmarks</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

<p>&copy;2010 <a href="http://blog.mugunthkumar.com">MK Blog</a>. All Rights Reserved.</p>.

<p>Related posts:<ol><li><a href='http://blog.mugunthkumar.com/coding/iphone-tutorial-enabling-reviewers-to-use-your-in-app-purchases-for-free/' rel='bookmark' title='Permanent Link: iPhone Tutorial &#8211; Enabling reviewers to use your In-App purchases for free'>iPhone Tutorial &#8211; Enabling reviewers to use your In-App purchases for free</a> <small>In-App purchases is a great way for developers to upsell...</small></li>
<li><a href='http://blog.mugunthkumar.com/coding/iphone-tutorial-uisearchdisplaycontroller-with-nspredicate/' rel='bookmark' title='Permanent Link: iPhone Tutorial &#8211; UISearchDisplayController with NSPredicate'>iPhone Tutorial &#8211; UISearchDisplayController with NSPredicate</a> <small>Though UISearchDisplayController is seemingly easy (and yes it&#8217;s easy), apart...</small></li>
<li><a href='http://blog.mugunthkumar.com/coding/iphone-tutorial-follow-cost-api-and-a-open-source-wrapper/' rel='bookmark' title='Permanent Link: iPhone Tutorial: Follow Cost API and a open source wrapper'>iPhone Tutorial: Follow Cost API and a open source wrapper</a> <small>What is Follow Cost? Follow Cost is a interesting and...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.mugunthkumar.com/coding/iphone-tutorial-%e2%80%93-in-app-purchases/feed/</wfw:commentRss>
		<slash:comments>221</slash:comments>
		</item>
		<item>
		<title>bit.ly wrapper for Objective-C/iPhone</title>
		<link>http://blog.mugunthkumar.com/coding/bit-ly-wrapper-objective-c-iphone/</link>
		<comments>http://blog.mugunthkumar.com/coding/bit-ly-wrapper-objective-c-iphone/#comments</comments>
		<pubDate>Sat, 26 Sep 2009 04:00:44 +0000</pubDate>
		<dc:creator>Mugunth Kumar</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[bit.ly]]></category>
		<category><![CDATA[iphone dev]]></category>
		<category><![CDATA[objective c]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://blog.mugunthkumar.com/?p=402</guid>
		<description><![CDATA[Continuing from my part 1, in this section, we will discuss about how to use this helper in your own application. Source Code Download the source code here MKBitlyHelper 1.0.zip Documentation With just three lines of code, you can shorten your URL using this wrapper. Initialize the helper class with your loginname and apikey. bitlyHelper [...]


Related posts:<ol><li><a href='http://blog.mugunthkumar.com/coding/consuming-a-restful-service-bit-ly-in-an-iphone-application/' rel='bookmark' title='Permanent Link: Consuming a RESTful Service (bit.ly) in an iPhone Application'>Consuming a RESTful Service (bit.ly) in an iPhone Application</a> <small>bit-ly-rest-api-objective-c Introduction Of late, many programmers who develop for Windows/Linux...</small></li>
<li><a href='http://blog.mugunthkumar.com/coding/iphone-tutorial-follow-cost-api-and-a-open-source-wrapper/' rel='bookmark' title='Permanent Link: iPhone Tutorial: Follow Cost API and a open source wrapper'>iPhone Tutorial: Follow Cost API and a open source wrapper</a> <small>What is Follow Cost? Follow Cost is a interesting and...</small></li>
<li><a href='http://blog.mugunthkumar.com/coding/formatting-dates-relative-to-now-objective-c-iphone/' rel='bookmark' title='Permanent Link: Formatting Dates relative to Now &#8211; Objective C (iPhone)'>Formatting Dates relative to Now &#8211; Objective C (iPhone)</a> <small>Many a times, in an iPhone application, you might need...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Continuing from my <a href="http://blog.mugunthkumar.com/coding/consuming-a-restful-service-bit-ly-in-an-iphone-application">part 1</a>, in this section, we will discuss about how to use this helper in your own application.</p>
<h3>Source Code</h3>
<p>Download the source code here<br />
<a href="http://blog.mugunthkumar.com/wp-content/uploads/MKBitlyHelper-v1.0.zip">MKBitlyHelper 1.0.zip</a></p>
<h3>Documentation</h3>
<p>With just three lines of code, you can shorten your URL using this wrapper.</p>
<p>Initialize the helper class with your loginname and apikey.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">bitlyHelper <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>MKBitlyHelper alloc<span style="color: #002200;">&#93;</span> initWithLoginName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;yourlogin&quot;</span> andAPIKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;yourapi&quot;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>In your application, you can either provide your application specific API or user provided API. Logging into the bit.ly api helps in tracking the click throughs and referrals. The classes doesn&#8217;t provide a login or APIKey by itself.</p>
<p>Now, shortening or expanding URLs is as easy as calling these functions.</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>shortURL <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>bitlyHelper shortenURL<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;http://mugunthkumar.com&quot;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>longURL <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>bitlyHelper expandURL<span style="color: #002200;">:</span>shortURL<span style="color: #002200;">&#93;</span>;</pre></div></div>

<h3>Disclaimers and other yada yada&#8230;</h3>
<p>Be forewarned that it may have errors. As Donald Knuth says,</p>
<blockquote><p>Beware of bugs in the above code; I have only proved it correct, not tried it.</p></blockquote>
<p>Feel free you use this code and re-distribute it. The source code must retain the copyrights and my attribution in any derivative works of the source code.</p>
<p>On your application, you might opt to attribute me in your app though it&#8217;s not mandatory. I would be happy if you do so <img src='http://blog.mugunthkumar.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><map name='google_ad_map_402_8b86e81420c6776e'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/402?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_402_8b86e81420c6776e' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=402&amp;url= http%3A%2F%2Fblog.mugunthkumar.com%2Fcoding%2Fbit-ly-wrapper-objective-c-iphone%2F' /></p>

<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-wealth">
<ul class="socials">
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=bit.ly+wrapper+for+Objective-C%2FiPhone+-+http://mk.sg/q&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://blog.mugunthkumar.com/coding/bit-ly-wrapper-objective-c-iphone/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-googlereader">
			<a href="http://www.google.com/reader/link?url=http://blog.mugunthkumar.com/coding/bit-ly-wrapper-objective-c-iphone/&amp;title=bit.ly+wrapper+for+Objective-C%2FiPhone&amp;srcUrl=http://blog.mugunthkumar.com/coding/bit-ly-wrapper-objective-c-iphone/&amp;srcTitle=bit.ly+wrapper+for+Objective-C%2FiPhone&amp;snippet=Continuing%20from%20my%20part%201%2C%20in%20this%20section%2C%20we%20will%20discuss%20about%20how%20to%20use%20this%20helper%20in%20your%20own%20application.%0D%0ASource%20Code%0D%0ADownload%20the%20source%20code%20here%0D%0AMKBitlyHelper%201.0.zip%0D%0ADocumentation%0D%0AWith%20just%20three%20lines%20of%20code%2C%20you%20can%20shorten%20your%20URL%20using%20this%20wrapper.%0D%0A%0D%0AInitialize%20the%20helper%20cl" rel="nofollow" class="external" title="Add this to Google Reader">Add this to Google Reader</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://blog.mugunthkumar.com/coding/bit-ly-wrapper-objective-c-iphone/&amp;title=bit.ly+wrapper+for+Objective-C%2FiPhone" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://blog.mugunthkumar.com/coding/bit-ly-wrapper-objective-c-iphone/&amp;t=bit.ly+wrapper+for+Objective-C%2FiPhone" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-friendfeed">
			<a href="http://www.friendfeed.com/share?title=bit.ly+wrapper+for+Objective-C%2FiPhone&amp;link=http://blog.mugunthkumar.com/coding/bit-ly-wrapper-objective-c-iphone/" rel="nofollow" class="external" title="Share this on FriendFeed">Share this on FriendFeed</a>
		</li>
		<li class="shr-gmail">
			<a href="https://mail.google.com/mail/?ui=2&amp;view=cm&amp;fs=1&amp;tf=1&amp;su=bit.ly+wrapper+for+Objective-C%2FiPhone&amp;body=Link: http://blog.mugunthkumar.com/coding/bit-ly-wrapper-objective-c-iphone/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A Continuing%20from%20my%20part%201%2C%20in%20this%20section%2C%20we%20will%20discuss%20about%20how%20to%20use%20this%20helper%20in%20your%20own%20application.%0D%0ASource%20Code%0D%0ADownload%20the%20source%20code%20here%0D%0AMKBitlyHelper%201.0.zip%0D%0ADocumentation%0D%0AWith%20just%20three%20lines%20of%20code%2C%20you%20can%20shorten%20your%20URL%20using%20this%20wrapper.%0D%0A%0D%0AInitialize%20the%20helper%20cl" rel="nofollow" class="external" title="Email this via Gmail">Email this via Gmail</a>
		</li>
		<li class="shr-googlebookmarks">
			<a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://blog.mugunthkumar.com/coding/bit-ly-wrapper-objective-c-iphone/&amp;title=bit.ly+wrapper+for+Objective-C%2FiPhone" rel="nofollow" class="external" title="Add this to Google Bookmarks">Add this to Google Bookmarks</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

<p>&copy;2010 <a href="http://blog.mugunthkumar.com">MK Blog</a>. All Rights Reserved.</p>.

<p>Related posts:<ol><li><a href='http://blog.mugunthkumar.com/coding/consuming-a-restful-service-bit-ly-in-an-iphone-application/' rel='bookmark' title='Permanent Link: Consuming a RESTful Service (bit.ly) in an iPhone Application'>Consuming a RESTful Service (bit.ly) in an iPhone Application</a> <small>bit-ly-rest-api-objective-c Introduction Of late, many programmers who develop for Windows/Linux...</small></li>
<li><a href='http://blog.mugunthkumar.com/coding/iphone-tutorial-follow-cost-api-and-a-open-source-wrapper/' rel='bookmark' title='Permanent Link: iPhone Tutorial: Follow Cost API and a open source wrapper'>iPhone Tutorial: Follow Cost API and a open source wrapper</a> <small>What is Follow Cost? Follow Cost is a interesting and...</small></li>
<li><a href='http://blog.mugunthkumar.com/coding/formatting-dates-relative-to-now-objective-c-iphone/' rel='bookmark' title='Permanent Link: Formatting Dates relative to Now &#8211; Objective C (iPhone)'>Formatting Dates relative to Now &#8211; Objective C (iPhone)</a> <small>Many a times, in an iPhone application, you might need...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.mugunthkumar.com/coding/bit-ly-wrapper-objective-c-iphone/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Formatting Dates relative to Now &#8211; Objective C (iPhone)</title>
		<link>http://blog.mugunthkumar.com/coding/formatting-dates-relative-to-now-objective-c-iphone/</link>
		<comments>http://blog.mugunthkumar.com/coding/formatting-dates-relative-to-now-objective-c-iphone/#comments</comments>
		<pubDate>Sat, 29 Aug 2009 16:42:08 +0000</pubDate>
		<dc:creator>Mugunth Kumar</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[iphone dev]]></category>
		<category><![CDATA[objective c]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://blog.mugunthkumar.com/?p=454</guid>
		<description><![CDATA[Many a times, in an iPhone application, you might need to format the date relative to today. This code snippet will help you do it. + &#40;NSString *&#41; formattedDateRelativeToNow:&#40;NSDate *&#41;date &#123; NSDateFormatter *mdf = &#91;&#91;NSDateFormatter alloc&#93; init&#93;; &#91;mdf setDateFormat:@&#34;yyyy-MM-dd&#34;&#93;; NSDate *midnight = &#91;mdf dateFromString:&#91;mdf stringFromDate:date&#93;&#93;; &#91;mdf release&#93;; &#160; NSInteger dayDiff = &#40;int&#41;&#91;midnight timeIntervalSinceNow&#93; / &#40;60*60*24&#41;; [...]


Related posts:<ol><li><a href='http://blog.mugunthkumar.com/coding/bit-ly-wrapper-objective-c-iphone/' rel='bookmark' title='Permanent Link: bit.ly wrapper for Objective-C/iPhone'>bit.ly wrapper for Objective-C/iPhone</a> <small>Continuing from my part 1, in this section, we will...</small></li>
<li><a href='http://blog.mugunthkumar.com/coding/consuming-a-restful-service-bit-ly-in-an-iphone-application/' rel='bookmark' title='Permanent Link: Consuming a RESTful Service (bit.ly) in an iPhone Application'>Consuming a RESTful Service (bit.ly) in an iPhone Application</a> <small>bit-ly-rest-api-objective-c Introduction Of late, many programmers who develop for Windows/Linux...</small></li>
<li><a href='http://blog.mugunthkumar.com/coding/iphone-tutorial-how-to-send-in-app-sms/' rel='bookmark' title='Permanent Link: iPhone Tutorial: How to send In-App SMS'>iPhone Tutorial: How to send In-App SMS</a> <small>Officially, iPhone OS 4 is out of NDA and I...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Many a times, in an iPhone application, you might need to format the date relative to today. This code snippet will help you do it.</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: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> formattedDateRelativeToNow<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSDate</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>date
<span style="color: #002200;">&#123;</span>
		<span style="color: #400080;">NSDateFormatter</span> <span style="color: #002200;">*</span>mdf <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSDateFormatter</span> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>mdf setDateFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;yyyy-MM-dd&quot;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #400080;">NSDate</span> <span style="color: #002200;">*</span>midnight <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>mdf dateFromString<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>mdf stringFromDate<span style="color: #002200;">:</span>date<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>mdf release<span style="color: #002200;">&#93;</span>;
&nbsp;
	NSInteger dayDiff <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span>midnight timeIntervalSinceNow<span style="color: #002200;">&#93;</span> <span style="color: #002200;">/</span> <span style="color: #002200;">&#40;</span><span style="color: #2400d9;">60</span><span style="color: #002200;">*</span><span style="color: #2400d9;">60</span><span style="color: #002200;">*</span><span style="color: #2400d9;">24</span><span style="color: #002200;">&#41;</span>;	
	<span style="color: #400080;">NSDateFormatter</span> <span style="color: #002200;">*</span>dateFormatter <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSDateFormatter</span> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;	
&nbsp;
	<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>dayDiff <span style="color: #002200;">==</span> <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span> 
		<span style="color: #002200;">&#91;</span>dateFormatter setDateFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;'Today, 'h':'mm aaa&quot;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>dayDiff <span style="color: #002200;">==</span> <span style="color: #002200;">-</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#41;</span> 
		<span style="color: #002200;">&#91;</span>dateFormatter setDateFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;'Yesterday, 'h':'mm aaa&quot;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>dayDiff <span style="color: #002200;">==</span> <span style="color: #002200;">-</span><span style="color: #2400d9;">2</span><span style="color: #002200;">&#41;</span> 
		<span style="color: #002200;">&#91;</span>dateFormatter setDateFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;MMMM d', Two days ago'&quot;</span><span style="color: #002200;">&#93;</span>; 	
	<span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>dayDiff &gt; <span style="color: #002200;">-</span><span style="color: #2400d9;">7</span> <span style="color: #002200;">&amp;&amp;</span> dayDiff &lt;<span style="color: #002200;">=</span> <span style="color: #002200;">-</span><span style="color: #2400d9;">2</span><span style="color: #002200;">&#41;</span> 
		<span style="color: #002200;">&#91;</span>dateFormatter setDateFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;MMMM d', This week'&quot;</span><span style="color: #002200;">&#93;</span>; 
	<span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>dayDiff &gt; <span style="color: #002200;">-</span><span style="color: #2400d9;">14</span> <span style="color: #002200;">&amp;&amp;</span> dayDiff &lt;<span style="color: #002200;">=</span> <span style="color: #002200;">-</span><span style="color: #2400d9;">7</span><span style="color: #002200;">&#41;</span> 
		<span style="color: #002200;">&#91;</span>dateFormatter setDateFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;MMMM d'; Last week'&quot;</span><span style="color: #002200;">&#93;</span>; 
	<span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>dayDiff &gt;<span style="color: #002200;">=</span> <span style="color: #002200;">-</span><span style="color: #2400d9;">60</span> <span style="color: #002200;">&amp;&amp;</span> dayDiff &lt;<span style="color: #002200;">=</span> <span style="color: #002200;">-</span><span style="color: #2400d9;">30</span><span style="color: #002200;">&#41;</span> 
		<span style="color: #002200;">&#91;</span>dateFormatter setDateFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;MMMM d'; Last month'&quot;</span><span style="color: #002200;">&#93;</span>; 
	<span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>dayDiff &gt;<span style="color: #002200;">=</span> <span style="color: #002200;">-</span><span style="color: #2400d9;">90</span> <span style="color: #002200;">&amp;&amp;</span> dayDiff &lt;<span style="color: #002200;">=</span> <span style="color: #002200;">-</span><span style="color: #2400d9;">60</span><span style="color: #002200;">&#41;</span> 
		<span style="color: #002200;">&#91;</span>dateFormatter setDateFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;MMMM d'; Within last three months'&quot;</span><span style="color: #002200;">&#93;</span>; 
	<span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>dayDiff &gt;<span style="color: #002200;">=</span> <span style="color: #002200;">-</span><span style="color: #2400d9;">180</span> <span style="color: #002200;">&amp;&amp;</span> dayDiff &lt;<span style="color: #002200;">=</span> <span style="color: #002200;">-</span><span style="color: #2400d9;">90</span><span style="color: #002200;">&#41;</span> 
		<span style="color: #002200;">&#91;</span>dateFormatter setDateFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;MMMM d'; Within last six months'&quot;</span><span style="color: #002200;">&#93;</span>; 
	<span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>dayDiff &gt;<span style="color: #002200;">=</span> <span style="color: #002200;">-</span><span style="color: #2400d9;">365</span> <span style="color: #002200;">&amp;&amp;</span> dayDiff &lt;<span style="color: #002200;">=</span> <span style="color: #002200;">-</span><span style="color: #2400d9;">180</span><span style="color: #002200;">&#41;</span> 
		<span style="color: #002200;">&#91;</span>dateFormatter setDateFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;MMMM d, YYYY'; Within this year'&quot;</span><span style="color: #002200;">&#93;</span>; 
	<span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>dayDiff &lt; <span style="color: #002200;">-</span><span style="color: #2400d9;">365</span><span style="color: #002200;">&#41;</span> 
		<span style="color: #002200;">&#91;</span>dateFormatter setDateFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;MMMM d, YYYY'; A long time ago'&quot;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>dateFormatter stringFromDate<span style="color: #002200;">:</span>date<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>Link back if you liked it&#8230;</p>
<p>&#8211;Mugunth</p>
<p><map name='google_ad_map_454_8b86e81420c6776e'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/454?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_454_8b86e81420c6776e' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=454&amp;url= http%3A%2F%2Fblog.mugunthkumar.com%2Fcoding%2Fformatting-dates-relative-to-now-objective-c-iphone%2F' /></p>

<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-wealth">
<ul class="socials">
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Formatting+Dates+relative+to+Now+-+Objective+C+%28iPhone%29+-+http://mk.sg/p&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://blog.mugunthkumar.com/coding/formatting-dates-relative-to-now-objective-c-iphone/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-googlereader">
			<a href="http://www.google.com/reader/link?url=http://blog.mugunthkumar.com/coding/formatting-dates-relative-to-now-objective-c-iphone/&amp;title=Formatting+Dates+relative+to+Now+-+Objective+C+%28iPhone%29&amp;srcUrl=http://blog.mugunthkumar.com/coding/formatting-dates-relative-to-now-objective-c-iphone/&amp;srcTitle=Formatting+Dates+relative+to+Now+-+Objective+C+%28iPhone%29&amp;snippet=Many%20a%20times%2C%20in%20an%20iPhone%20application%2C%20you%20might%20need%20to%20format%20the%20date%20relative%20to%20today.%20This%20code%20snippet%20will%20help%20you%20do%20it.%0D%0A%0D%0A%0D%0A%2B%20%28NSString%20%2A%29%20formattedDateRelativeToNow%3A%28NSDate%20%2A%29date%0D%0A%7B%0D%0A%09%09NSDateFormatter%20%2Amdf%20%3D%20%5B%5BNSDateFormatter%20alloc%5D%20init%5D%3B%0D%0A%09%5Bmdf%20setDateFormat%3A%40%22yyyy-MM-dd%22%5D%3B%0D%0A%09NSDate" rel="nofollow" class="external" title="Add this to Google Reader">Add this to Google Reader</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://blog.mugunthkumar.com/coding/formatting-dates-relative-to-now-objective-c-iphone/&amp;title=Formatting+Dates+relative+to+Now+-+Objective+C+%28iPhone%29" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://blog.mugunthkumar.com/coding/formatting-dates-relative-to-now-objective-c-iphone/&amp;t=Formatting+Dates+relative+to+Now+-+Objective+C+%28iPhone%29" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-friendfeed">
			<a href="http://www.friendfeed.com/share?title=Formatting+Dates+relative+to+Now+-+Objective+C+%28iPhone%29&amp;link=http://blog.mugunthkumar.com/coding/formatting-dates-relative-to-now-objective-c-iphone/" rel="nofollow" class="external" title="Share this on FriendFeed">Share this on FriendFeed</a>
		</li>
		<li class="shr-gmail">
			<a href="https://mail.google.com/mail/?ui=2&amp;view=cm&amp;fs=1&amp;tf=1&amp;su=Formatting+Dates+relative+to+Now+-+Objective+C+%28iPhone%29&amp;body=Link: http://blog.mugunthkumar.com/coding/formatting-dates-relative-to-now-objective-c-iphone/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A Many%20a%20times%2C%20in%20an%20iPhone%20application%2C%20you%20might%20need%20to%20format%20the%20date%20relative%20to%20today.%20This%20code%20snippet%20will%20help%20you%20do%20it.%0D%0A%0D%0A%0D%0A%2B%20%28NSString%20%2A%29%20formattedDateRelativeToNow%3A%28NSDate%20%2A%29date%0D%0A%7B%0D%0A%09%09NSDateFormatter%20%2Amdf%20%3D%20%5B%5BNSDateFormatter%20alloc%5D%20init%5D%3B%0D%0A%09%5Bmdf%20setDateFormat%3A%40%22yyyy-MM-dd%22%5D%3B%0D%0A%09NSDate" rel="nofollow" class="external" title="Email this via Gmail">Email this via Gmail</a>
		</li>
		<li class="shr-googlebookmarks">
			<a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://blog.mugunthkumar.com/coding/formatting-dates-relative-to-now-objective-c-iphone/&amp;title=Formatting+Dates+relative+to+Now+-+Objective+C+%28iPhone%29" rel="nofollow" class="external" title="Add this to Google Bookmarks">Add this to Google Bookmarks</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

<p>&copy;2010 <a href="http://blog.mugunthkumar.com">MK Blog</a>. All Rights Reserved.</p>.

<p>Related posts:<ol><li><a href='http://blog.mugunthkumar.com/coding/bit-ly-wrapper-objective-c-iphone/' rel='bookmark' title='Permanent Link: bit.ly wrapper for Objective-C/iPhone'>bit.ly wrapper for Objective-C/iPhone</a> <small>Continuing from my part 1, in this section, we will...</small></li>
<li><a href='http://blog.mugunthkumar.com/coding/consuming-a-restful-service-bit-ly-in-an-iphone-application/' rel='bookmark' title='Permanent Link: Consuming a RESTful Service (bit.ly) in an iPhone Application'>Consuming a RESTful Service (bit.ly) in an iPhone Application</a> <small>bit-ly-rest-api-objective-c Introduction Of late, many programmers who develop for Windows/Linux...</small></li>
<li><a href='http://blog.mugunthkumar.com/coding/iphone-tutorial-how-to-send-in-app-sms/' rel='bookmark' title='Permanent Link: iPhone Tutorial: How to send In-App SMS'>iPhone Tutorial: How to send In-App SMS</a> <small>Officially, iPhone OS 4 is out of NDA and I...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.mugunthkumar.com/coding/formatting-dates-relative-to-now-objective-c-iphone/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Consuming a RESTful Service (bit.ly) in an iPhone Application</title>
		<link>http://blog.mugunthkumar.com/coding/consuming-a-restful-service-bit-ly-in-an-iphone-application/</link>
		<comments>http://blog.mugunthkumar.com/coding/consuming-a-restful-service-bit-ly-in-an-iphone-application/#comments</comments>
		<pubDate>Fri, 14 Aug 2009 04:00:39 +0000</pubDate>
		<dc:creator>Mugunth Kumar</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[bit.ly]]></category>
		<category><![CDATA[iphone dev]]></category>
		<category><![CDATA[objective c]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://blog.mugunthkumar.com/?p=352</guid>
		<description><![CDATA[bit-ly-rest-api-objective-c Introduction Of late, many programmers who develop for Windows/Linux have moved to iPhone because of it's runaway success. Among the most successful apps on the Apple AppStore, first comes games (yeah I can hear you, fart apps!!!). Next comes apps like Tweetie and others those consume a web service (REST or otherwise). Games are [...]


Related posts:<ol><li><a href='http://blog.mugunthkumar.com/coding/bit-ly-wrapper-objective-c-iphone/' rel='bookmark' title='Permanent Link: bit.ly wrapper for Objective-C/iPhone'>bit.ly wrapper for Objective-C/iPhone</a> <small>Continuing from my part 1, in this section, we will...</small></li>
<li><a href='http://blog.mugunthkumar.com/coding/iphone-tutorial-follow-cost-api-and-a-open-source-wrapper/' rel='bookmark' title='Permanent Link: iPhone Tutorial: Follow Cost API and a open source wrapper'>iPhone Tutorial: Follow Cost API and a open source wrapper</a> <small>What is Follow Cost? Follow Cost is a interesting and...</small></li>
<li><a href='http://blog.mugunthkumar.com/coding/formatting-dates-relative-to-now-objective-c-iphone/' rel='bookmark' title='Permanent Link: Formatting Dates relative to Now &#8211; Objective C (iPhone)'>Formatting Dates relative to Now &#8211; Objective C (iPhone)</a> <small>Many a times, in an iPhone application, you might need...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><code><a style="display:none" rel="tag" href="http://blog.mugunthkumar.com/coding/consuming-a-restful-service-bit-ly-in-an-iphone-application"> bit-ly-rest-api-objective-c </a></p>
<h2>Introduction</h2>
<p>Of late, many programmers who develop for Windows/Linux have moved to iPhone because of it's runaway success. Among the most successful apps on the Apple AppStore, first comes games (yeah I can hear you, fart apps!!!). Next comes apps like Tweetie and others those consume a web service (REST or otherwise). Games are pretty difficult get started especially if you aren't a game programmer. However, developing iPhone applications that consume a web service is quite easy. In this article, I'll illustrate how to write a iPhone application to consume a web service. I'll take bit.ly's REST service as an example, and at the end, we will be developing a nice "bit.ly" wrapper in Objective-C. For those who are new to REST, it stands for Representational State Transfer. Head on to Wikipedia <a href="http://en.wikipedia.org/wiki/Representational_State_Transfer" target="_blank">here</a> for more details. The post itself is split into two parts, one focussing XML and the other JSON.<br />
At the end of the second part, you can download the source code attached.</p>
<h2>Bit.ly Documentation</h2>
<p>Bit.ly, as you all know is a URL shortening service, that became popular all of a sudden when Twitter started using bit.ly as it's default URL shortening service over tinyurl.com. The REST documentation of bit.ly is available from Google code <a href="http://code.google.com/p/bitly-api/wiki/ApiDocumentation">here</a>.</p>
<h2>Some Basics before we dirty our hands with real code</h2>
<h3>Authentication Types</h3>
<p>bit.ly (and many such services) use a kind of HTTP authentication called Basic Authentication. In basic authentication, the username and password that is typed into the client is formatted as<br />
: and the concatenated string is converted to "base64" encoding. This string is passed along with the HTTP Header usually in every API call that does some function which you have to normally log on to see.<br />
There is one more type of authentication, oAuth, which stands from Open Authentication. As of now, bit.ly doesn't use oAuth. Explaining oAuth itself needs a separate article and is outside the scope of this article.</p>
<h3>HTTP Request types</h3>
<p>When you access a RESTful service, you either request data or post data. In most cases, your HTTP Request type is either a "GET" or a "POST". There are two more types of requests and they are, "PUT" and "DELETE". When to use what, is upto the designer of the RESTful service. You as a consumer, just follow the documentation.<br />
In our case, bit.ly we will be using only "GET" methods.</p>
<h2>The real code</h2>
<p>You shouldn't be shocked to know that, accessing a RESTful service for data is just a matter of 10 line code.<br />
<code>NSString *longURL = @"http://mugunthkumar.com"<br />
NSString *baseURLString =<br />
    @"http://api.bit.ly/shorten?version=2.0.1&amp;longUrl=%@&amp;login=bitlyapidemo&amp;apiKey=";<br />
NSString *urlString = [[NSString alloc] initWithFormat:@"%@%@",<br />
baseURLString, longURL];<br />
NSURL *url = [[NSURL alloc] initWithString:urlString];<br />
NSString *result = [[NSString alloc] initWithContentsOfURL:url];</pre>
<p>NSLog(result);<br />
[url release];<br />
[urlString release];<br />
[result release];</code></p>
<h2>Parsing the Result</h2>
<p>The result which we "NSLogged" here could be either XML or JSON. In our case, bit.ly by default sends JSON formatted data, which is by far the most commonly used. JSON is lighter than XML for transferring the same amount of data. There are a lot of debate going along on which is good for data transfer. I personally prefer JSON. Of late, JSON is picking up over XML with the advent of JSON parsers. Objective C has a very robust JSON parser called <a href="http://code.google.com/p/json-framework/">json-framework</a>. We will touch about them later in the next part of this article. The other kind of data format namely XML, is returned by bit.ly, only when you pass</p>
<pre>format=xml</pre>
<p>along with the URL as an additional parameter. For parsing XML, there are two parsers. One is NSXMLParser and the other is a faster libxml2. Though libxml2 is faster, use it on your iPhone app only when you are going to parse over 10MB of XML data. When your XML data is small (as in our case), the performance gap between NSXMLParser and libxml2 is very meagre. In case of bit.ly, the shorten api returns &lt; 1KB of data. Most RESTful service return very little data (mostly in the order of few hundred kilo bytes) I prefer NSXMLParser for one reason. You code is cleaner than it would be if you use libxml2. In this article, I'll go take you through both ways of handling the data.</p>
<h3>Parsing XML</h3>
<p><code>[parser initWithContentsOfURL: url];<br />
[parser setDelegate:self];</p>
<p>[parser setShouldProcessNamespaces:NO];<br />
[parser setShouldReportNamespacePrefixes:NO];<br />
[parser setShouldResolveExternalEntities:NO];</p>
<p>[parser parse];<br />
[parser release];</code><br />
Parsing XML data using NSXMLParser couldn't be simpler. You just have to create an object (parser) of type NSXMLParser, initialize it and call parse.</p>
<h4>Things to note</h4>
<p>However, there are a couple of things to note.</p>
<p>1) You can initialize the parser object either with NSURL or with NSData. Both methods work equally well.<br />
2) You OUGHT to set the delegate to self. Otherwise there is no way for the NSXMLParser to notify you of events.<br />
3) The next three lines are optional. You usually set it to YES if you want to get notified of those events as well.<br />
4) The call to [parser parse] is blocking. This means, it will not return until the complete content is parsed. So, you can (and should) release any associated memory at the next line.</p>
<h4>Callbacks from NSXMLParser</h4>
<p>NSXMLParser has around 14 callback methods. But it's enough if you implement just three of them. They are,</p>
<pre>parser:didStartElement:namespaceURI:qualifiedName:attributes:
parser:didEndElement:namespaceURI:qualifiedName:
parser:foundCharacters:</pre>
<p>The didStartElement is called when the XMLParser encounters a opening XML element. You usually initialize temporary variables and read attributes if any in this function. In case of bit.ly, you just have to read the "shortUrl" element. Just handling this element alone will do.</p>
<div id="attachment_380" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.mugunthkumar.com/wp-content/uploads/bitly1.png"><img class="size-medium wp-image-380" title="bitly" src="http://blog.mugunthkumar.com/wp-content/uploads/bitly1-300x259.png" alt="ShortURL from bit.ly" width="300" height="259" /></a><p class="wp-caption-text">ShortURL from bit.ly</p></div>
<p>Declare the following NSStrings, currentShortURL, actualShortURL and currentElement.<br />
Write the following code into the didStartElement Block.<br />
<code>- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict<br />
{<br />
currentElement = [[elementName copy] autorelease];<br />
if ([elementName isEqualToString:@"shortUrl"]) {<br />
		currentShortURLString = [[NSString alloc] init];<br />
}</code><br />
Now, in the foundCharacters block, write the following code.<br />
<code>- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{<br />
if ([currentElement isEqualToString:@"shortURL"]) {<br />
		[currentShortURLString appendString:string];<br />
}</code><br />
In the didEndElement block write,<br />
<code>- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName<br />
{<br />
	if ([elementName isEqualToString:@"shortURL"]) {</p>
<p>	actualURLString = currentURLString;<br />
}</code><br />
Now when the parsing ends, just after the [parser release] function, actualShortURLString will contain the shortened URL.</p>
<p>End of story. If you couldn't follow the code in this blog post, you can always download the source code attached (in next part). For more detailed information on parsing using NSXMLParser follow <a href="http://codesofa.com/blog/archive/2008/07/23/make-nsxmlparser-your-friend.html">this article</a>.</p>
<h3>Parsing JSON</h3>
<p>Parsing JSON is much simpler than XML. In fact, I hate to call it as "parsing" as you don't even have to write a parser!!! By using the <a href="http://code.google.com/p/json-framework/">open source json-framework kit for iPhone</a> you can easily "convert" a JSON string into a NSDictionary. Now let's have a look at the code.</p>
<h3>JSON Parsing Code</h3>
<p>JSON Parsing is far much simpler than XML. Infact, the code attached below uses JSON.</p>
<p>Parsing the bitly information is as simple as writing these three lines of code.<br />
<code>SBJSON *jsonParser = [SBJSON new];<br />
NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];<br />
NSDictionary *dict = (NSDictionary*)[jsonParser objectWithString:jsonString];</code><br />
The return string is a dictionary of key value pairs.To read a value, you can call objectForKey function within NSDictionary.</p>
<p>In most cases, including bit.ly, JSON return strings always contain other dictionaries nested within itself. To read a value within a dictionary, just nest your calls  like this.<br />
<code>NSString *shortURL = [[[dict objectForKey:@"results"]<br />
objectForKey:f_longURL]<br />
objectForKey:@"shortUrl"];</code></p>
<h3>Source Code and Documentation</h3>
<p>The source code and documentation on how to use this is explained in <a href="http://blog.mugunthkumar.com/coding/bit-ly-wrapper-objective-c-iphone/">post 2</a>.</code></p>
<p><map name='google_ad_map_352_8b86e81420c6776e'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/352?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_352_8b86e81420c6776e' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=352&amp;url= http%3A%2F%2Fblog.mugunthkumar.com%2Fcoding%2Fconsuming-a-restful-service-bit-ly-in-an-iphone-application%2F' /></p>

<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-wealth">
<ul class="socials">
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Consuming+a+RESTful+Service+%28bit.ly%29+in+an+iPhone+Application+-+http://mk.sg/h&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://blog.mugunthkumar.com/coding/consuming-a-restful-service-bit-ly-in-an-iphone-application/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-googlereader">
			<a href="http://www.google.com/reader/link?url=http://blog.mugunthkumar.com/coding/consuming-a-restful-service-bit-ly-in-an-iphone-application/&amp;title=Consuming+a+RESTful+Service+%28bit.ly%29+in+an+iPhone+Application&amp;srcUrl=http://blog.mugunthkumar.com/coding/consuming-a-restful-service-bit-ly-in-an-iphone-application/&amp;srcTitle=Consuming+a+RESTful+Service+%28bit.ly%29+in+an+iPhone+Application&amp;snippet=%20bit-ly-rest-api-objective-c%20%0AIntroduction%0AOf%20late%2C%20many%20programmers%20who%20develop%20for%20Windows%2FLinux%20have%20moved%20to%20iPhone%20because%20of%20it%27s%20runaway%20success.%20Among%20the%20most%20successful%20apps%20on%20the%20Apple%20AppStore%2C%20first%20comes%20games%20%28yeah%20I%20can%20hear%20you%2C%20fart%20apps%21%21%21%29.%20Next%20comes%20apps%20like%20Tweetie%20and%20other" rel="nofollow" class="external" title="Add this to Google Reader">Add this to Google Reader</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://blog.mugunthkumar.com/coding/consuming-a-restful-service-bit-ly-in-an-iphone-application/&amp;title=Consuming+a+RESTful+Service+%28bit.ly%29+in+an+iPhone+Application" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://blog.mugunthkumar.com/coding/consuming-a-restful-service-bit-ly-in-an-iphone-application/&amp;t=Consuming+a+RESTful+Service+%28bit.ly%29+in+an+iPhone+Application" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-friendfeed">
			<a href="http://www.friendfeed.com/share?title=Consuming+a+RESTful+Service+%28bit.ly%29+in+an+iPhone+Application&amp;link=http://blog.mugunthkumar.com/coding/consuming-a-restful-service-bit-ly-in-an-iphone-application/" rel="nofollow" class="external" title="Share this on FriendFeed">Share this on FriendFeed</a>
		</li>
		<li class="shr-gmail">
			<a href="https://mail.google.com/mail/?ui=2&amp;view=cm&amp;fs=1&amp;tf=1&amp;su=Consuming+a+RESTful+Service+%28bit.ly%29+in+an+iPhone+Application&amp;body=Link: http://blog.mugunthkumar.com/coding/consuming-a-restful-service-bit-ly-in-an-iphone-application/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A %20bit-ly-rest-api-objective-c%20%0AIntroduction%0AOf%20late%2C%20many%20programmers%20who%20develop%20for%20Windows%2FLinux%20have%20moved%20to%20iPhone%20because%20of%20it%27s%20runaway%20success.%20Among%20the%20most%20successful%20apps%20on%20the%20Apple%20AppStore%2C%20first%20comes%20games%20%28yeah%20I%20can%20hear%20you%2C%20fart%20apps%21%21%21%29.%20Next%20comes%20apps%20like%20Tweetie%20and%20other" rel="nofollow" class="external" title="Email this via Gmail">Email this via Gmail</a>
		</li>
		<li class="shr-googlebookmarks">
			<a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://blog.mugunthkumar.com/coding/consuming-a-restful-service-bit-ly-in-an-iphone-application/&amp;title=Consuming+a+RESTful+Service+%28bit.ly%29+in+an+iPhone+Application" rel="nofollow" class="external" title="Add this to Google Bookmarks">Add this to Google Bookmarks</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

<p>&copy;2010 <a href="http://blog.mugunthkumar.com">MK Blog</a>. All Rights Reserved.</p>.

<p>Related posts:<ol><li><a href='http://blog.mugunthkumar.com/coding/bit-ly-wrapper-objective-c-iphone/' rel='bookmark' title='Permanent Link: bit.ly wrapper for Objective-C/iPhone'>bit.ly wrapper for Objective-C/iPhone</a> <small>Continuing from my part 1, in this section, we will...</small></li>
<li><a href='http://blog.mugunthkumar.com/coding/iphone-tutorial-follow-cost-api-and-a-open-source-wrapper/' rel='bookmark' title='Permanent Link: iPhone Tutorial: Follow Cost API and a open source wrapper'>iPhone Tutorial: Follow Cost API and a open source wrapper</a> <small>What is Follow Cost? Follow Cost is a interesting and...</small></li>
<li><a href='http://blog.mugunthkumar.com/coding/formatting-dates-relative-to-now-objective-c-iphone/' rel='bookmark' title='Permanent Link: Formatting Dates relative to Now &#8211; Objective C (iPhone)'>Formatting Dates relative to Now &#8211; Objective C (iPhone)</a> <small>Many a times, in an iPhone application, you might need...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.mugunthkumar.com/coding/consuming-a-restful-service-bit-ly-in-an-iphone-application/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
