<?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/"
	
	xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Get Set Games &#187; NSBundle</title>
	<atom:link href="http://getsetgames.com/tag/nsbundle/feed/" rel="self" type="application/rss+xml" />
	<link>http://getsetgames.com</link>
	<description></description>
	<lastBuildDate>Thu, 12 Jan 2012 20:12:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/><cloud domain='getsetgames.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<link rel="http://api.friendfeed.com/2008/03#sup" xmlns="http://www.w3.org/2005/Atom" type="application/json" href="http://friendfeed.com/api/public-sup.json#5c973c50be"/>		<item>
		<title>How to Get Your App&#8217;s Display Name and Version</title>
		<link>http://getsetgames.com/2009/12/13/iphonedev-advent-tip-13-how-to-get-your-apps-display-name-and-version/</link>
		<comments>http://getsetgames.com/2009/12/13/iphonedev-advent-tip-13-how-to-get-your-apps-display-name-and-version/#comments</comments>
		<pubDate>Sun, 13 Dec 2009 17:46:00 +0000</pubDate>
		<dc:creator>Derek van Vliet</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[advent]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[NSBundle]]></category>
		<category><![CDATA[objective-c]]></category>

		<guid isPermaLink="false">http://getsetgames.com/?p=965</guid>
		<description><![CDATA[Have you ever needed to retrieve your iPhone app&#8217;s name or version at runtime? Sure, you can use constants in a lot of cases, but it can often save you [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever needed to retrieve your iPhone app&#8217;s name or version at runtime? Sure, you can use constants in a lot of cases, but it can often save you time in the long run to make use of the information that is available via a class called <strong>NSBundle</strong>.</p>
<h2>The Code</h2>
<p>You can retrieve your iPhone app&#8217;s display name using the following one line of code:</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>appName <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSBundle</span> mainBundle<span style="color: #002200;">&#93;</span> objectForInfoDictionaryKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;CFBundleDisplayName&quot;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>To retrieve your iPhone app&#8217;s version number, use the following similar line of code:</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>appVersion <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSBundle</span> mainBundle<span style="color: #002200;">&#93;</span> objectForInfoDictionaryKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;CFBundleVersion&quot;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<h2>Use Case</h2>
<p><img src="http://getsetgames.com/wp-content/uploads/2009/12/Screen-shot-2009-12-13-at-12.41.07-PM.png" alt="Screen shot 2009-12-13 at 12.41.07 PM" title="Screen shot 2009-12-13 at 12.41.07 PM" width="83" height="60" class="alignright size-full wp-image-973" />In <a href="http://getsetgames.com/games/addicus/">Addicus</a>, when you click the &#8220;Get Set&#8221; button on the main menu, it links to our website and passes in the referring application name and app version as querystring parameters, allowing us to track visits to our website from different versions of all of our iPhone games. To do this, we combine the above code with code that <a href="http://getsetgames.com/2009/12/01/iphonedev-advent-tip-1-how-to-open-a-url-in-safari/">opens a URL</a>. Here is the resulting code:</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>appName <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSBundle</span> mainBundle<span style="color: #002200;">&#93;</span> objectForInfoDictionaryKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;CFBundleDisplayName&quot;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>appVersion <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSBundle</span> mainBundle<span style="color: #002200;">&#93;</span> objectForInfoDictionaryKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;CFBundleVersion&quot;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>url <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;http://getsetgames.com/?r=%@&amp;v=%@&quot;</span>,appName,appVersion<span style="color: #002200;">&#93;</span>;
&nbsp;
<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: #002200;">&#91;</span><span style="color: #400080;">NSURL</span> URLWithString<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>url stringByAddingPercentEscapesUsingEncoding<span style="color: #002200;">:</span>NSUTF8StringEncoding<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>Since we&#8217;re retrieving this info via the NSBundle class, we never need to change this code when we update the version of the app. The version change propagates down to the URL we open automatically. And this code can be reused in any app without changing it. </p>
]]></content:encoded>
			<wfw:commentRss>http://getsetgames.com/2009/12/13/iphonedev-advent-tip-13-how-to-get-your-apps-display-name-and-version/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:thumbnail url="http://getsetgames.com/wp-content/uploads/2009/12/Screen-shot-2009-12-13-at-12.41.07-PM.png" />
		<media:content url="http://getsetgames.com/wp-content/uploads/2009/12/Screen-shot-2009-12-13-at-12.41.07-PM.png" medium="image">
			<media:title type="html">Screen shot 2009-12-13 at 12.41.07 PM</media:title>
		</media:content>
	</item>
	</channel>
</rss>

