<?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>Indie iPhone Development Blog &#187; Programming</title>
	<atom:link href="http://blog.indieiphonedev.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.indieiphonedev.com</link>
	<description>The musings of an independent iPhone developer</description>
	<lastBuildDate>Mon, 20 Jun 2011 18:48:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>On constructive critizism</title>
		<link>http://blog.indieiphonedev.com/2011/06/04/on-constructive-critizism/</link>
		<comments>http://blog.indieiphonedev.com/2011/06/04/on-constructive-critizism/#comments</comments>
		<pubDate>Sat, 04 Jun 2011 18:23:53 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Opinion]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[app review]]></category>
		<category><![CDATA[iPhone app]]></category>
		<category><![CDATA[iPhone OS]]></category>
		<category><![CDATA[objective-C]]></category>

		<guid isPermaLink="false">http://blog.indieiphonedev.com/?p=304</guid>
		<description><![CDATA[There has been a couple of blog posts lately regarding the bloggy criticism of iOS applications by other app developers as well as general tech bloggers. These posts seem to suggest that iOS developers should band together and not criticize each others applications. I generally agree with the statement &#8220;be excellent to each other&#8221; &#8211; [...]]]></description>
			<content:encoded><![CDATA[<p>There has been a couple of <a href="http://www.cimgf.com/2011/06/03/why-so-serious/">blog</a> <a href="http://iphonedevelopment.blogspot.com/2011/06/on-being-excellent-to-each-other.html">posts</a> lately regarding the bloggy criticism of iOS applications by other app developers as well as general tech bloggers.  These posts seem to suggest that iOS developers should band together and not criticize each others applications.  I generally agree with the statement &#8220;be excellent to each other&#8221; &#8211; but if that means patting each others backs and saying good job even if the application has flaws then the iOS platform is in trouble.  I think that one of the great things about the iOS platform is the constant push to make something that is greater and more amazing than what has been done before.<br />
<P><br />
Getting criticism, be it from users through app reviews or emails or from bloggers, is a great way to push everyone to make better applications.  I can clearly identify with the fact that developers have an emotional connection to the applications that they make.  None of my applications make a huge amount of money and my main motivation is to provide people with great tools to use on their phone &#8211; so getting emails or reviews saying &#8220;this app sucks&#8221; is a feeling not much different than helping a complete stranger just to have them spit at you.<br />
<P><br />
In my opinion, the app review system setup by Apple is one of the greatest innovations of the iOS platform and has been instrumental in the success of the App Store &#8211; before this the only way to give feedback was to email the developer and then they could do whatever they wanted &#8211; you had already paid for the app so they had no incentive to actually fix the issue.  With public reviews and a rating system the incentive to fix issues brought up is much greater and this is something that will push apps to become better.  Several times this has brought great new features to my apps and alerted me to features that were not as intuitive as I had originally thought.<br />
<P><br />
Like many other Apple enthusiasts I was very excited for the launch of The Daily.  Like many others I was disappointed at the initial product.  I think that a lot of people expected the app to be Apple Great (like Maps, Garage Band etc) because of the hype and media buildup for the app and the apparent endorsement of the app by Apple.  However, the app has several short falls <a href="http://blogs.telegraph.co.uk/technology/shanerichmond/100006286/the-daily-ipad-app-review-a-complete-failure-of-imagination/">which</a> <a href="http://technorati.com/technology/article/ipad-app-review-the-daily/">were</a> <a href="http://www.tuaw.com/2011/02/06/more-thoughts-on-the-daily/">pointed</a> <a href="http://daringfireball.net/linked/2011/02/02/the-daily-in-action">out</a> and <a href="http://daringfireball.net/linked/2011/02/06/brichter-daily">suggestions for improvements</a> with implementation were posted.  I do not understand why the developer of the app would be surprised that the app got a harsh reception when the developer admits himself that there were issues with the app that if they had longer time could have been sorted out.<br />
<P><br />
I hope that the iOS developer community is grown up enough that we can accept criticism of our work and that we can learn from this and all strive towards making excellent if not perfect apps.  </p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.indieiphonedev.com%2F2011%2F06%2F04%2Fon-constructive-critizism%2F&amp;title=On%20constructive%20critizism" id="wpa2a_2"><img src="http://blog.indieiphonedev.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.indieiphonedev.com/2011/06/04/on-constructive-critizism/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Implementing iAd in iPhone applications</title>
		<link>http://blog.indieiphonedev.com/2011/04/27/implementing-iad-in-iphone-applications/</link>
		<comments>http://blog.indieiphonedev.com/2011/04/27/implementing-iad-in-iphone-applications/#comments</comments>
		<pubDate>Wed, 27 Apr 2011 05:11:33 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[free app]]></category>
		<category><![CDATA[iAd]]></category>
		<category><![CDATA[iPad]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[objective-C]]></category>
		<category><![CDATA[source code]]></category>

		<guid isPermaLink="false">http://blog.indieiphonedev.com/?p=296</guid>
		<description><![CDATA[There are a couple of tricks to implementing iAd in iPhone applications that are not 100% spelled out in the documentation provided by Apple. If you do not implement right your app will crash on phones running older versions of iOS such as iOS4.1 and iOS3. For your .h file: In the .m file you [...]]]></description>
			<content:encoded><![CDATA[<p>There are a couple of tricks to implementing iAd in iPhone applications that are not 100% spelled out in the documentation provided by Apple.  If you do not implement right your app will crash on phones running older versions of iOS such as iOS4.1 and iOS3. </p>
<p>For your .h file:</p>
<pre class="brush: objc; title: ; notranslate">
#import &lt;UIKit/UIKit.h&gt;;
#import &lt;iAd/iAd.h&gt;;
@interface iAdViewController : UIViewController &lt;ADBannerViewDelegate&gt; {
	ADBannerView *adView;
 	BOOL bannerIsVisible;
}
@property (nonatomic,assign) BOOL bannerIsVisible;
@end
</pre>
<p>In the .m file you need the following:</p>
<pre class="brush: objc; title: ; notranslate">
- (void) viewWillAppear:(BOOL)animated {
	// check if iAd is available
	Class classAdBannerView = NSClassFromString(@&quot;ADBannerView&quot;);
	if (classAdBannerView) {
		// create iAd
		ADBannerView *bannerView = [[classAdBannerView alloc] initWithFrame:CGRectZero];

		if (&amp;ADBannerContentSizeIdentifierPortrait != nil) {
			// NEWER
			DLog(@&quot;NEWER&quot;);
			bannerView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait];
			bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
		} else {
			// OLDER
			DLog(@&quot;OLDER&quot;);
			bannerView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifier320x50];
			bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
		}

		bannerView.delegate=self;

		self.adView = bannerView;
		[self.view addSubview:adView];
		self.bannerIsVisible=NO;
		[bannerView release];

	}
	[super viewWillAppear: animated];
}
</pre>
<p>I am creating the bannerView programatically in order to have the app also work on pre iOS 4.1 devices.  The check for ADBannerContentSizeIdentifierPortrait is to see if the user is using iOS 4.1 or newer iOS.  In iOS 4.1 the identifiers were based on size &#8211; but in newer iOS the iPad got iAds and the size no longer made sense &#8211; thus the landscape/portrait designations.</p>
<p>Finally &#8211; if your app supports multiple interface orientations &#8211; you need to let the banner know that the device rotated so it can show the right size ad.</p>
<pre class="brush: objc; title: ; notranslate">
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

    if (&amp;ADBannerContentSizeIdentifierPortrait != nil) {
        // NEWER
		DLog(@&quot;NEWER&quot;);
        if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation))
            adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
        else
            adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
    } else {
        // OLDER
		DLog(@&quot;OLDER&quot;);
        if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation))
            adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier480x32;
        else
            adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
    }
}
</pre>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.indieiphonedev.com%2F2011%2F04%2F27%2Fimplementing-iad-in-iphone-applications%2F&amp;title=Implementing%20iAd%20in%20iPhone%20applications" id="wpa2a_4"><img src="http://blog.indieiphonedev.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.indieiphonedev.com/2011/04/27/implementing-iad-in-iphone-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to batch change volume of aif files</title>
		<link>http://blog.indieiphonedev.com/2011/01/15/how-to-batch-change-volume-of-aif-files/</link>
		<comments>http://blog.indieiphonedev.com/2011/01/15/how-to-batch-change-volume-of-aif-files/#comments</comments>
		<pubDate>Sat, 15 Jan 2011 17:42:12 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[batch]]></category>
		<category><![CDATA[iPhone app]]></category>
		<category><![CDATA[sounds]]></category>
		<category><![CDATA[sox]]></category>

		<guid isPermaLink="false">http://blog.indieiphonedev.com/?p=265</guid>
		<description><![CDATA[After creating aif files that tells the distance of upto 100 miles in both miles and kilometers (around 50 individual files) I tested the distance announcement while playing music and found that the volume of all my files was too low.  Now I could go in and manually increase the volume on each file &#8211; [...]]]></description>
			<content:encoded><![CDATA[<p>After creating aif files that tells the distance of upto 100 miles in both miles and kilometers (around 50 individual files) I tested the distance announcement while playing music and found that the volume of all my files was too low.  Now I could go in and manually increase the volume on each file &#8211; but that would be a bit of a pain and possibly not very consistent.  Besides one of the things computers are good at is doing the same task over and over again.  So I looked for a software solution.  Luckily there is a great open source command line sound manipulation software called &lt;a href=&#8221;http://sox.sourceforge.net/&#8221;&gt;SOX&lt;/a&gt;.  This tool has a function for gain which lets you set the gain of any files in decibels (dB).</p>
<p>To run this program on all files in a folder run the following command from the terminal after copying the sox program to the folder:</p>
<pre class="brush: objc; title: ; notranslate">
for i in *.aif; do ./sox $i ${i%.*}.aiff gain -n 8; done;
</pre>
<p>In the instance above the original files are .aif and they were converted to have the file extension .aiff.  I tried to overwrite the original file &#8211; but that did not work well.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.indieiphonedev.com%2F2011%2F01%2F15%2Fhow-to-batch-change-volume-of-aif-files%2F&amp;title=How%20to%20batch%20change%20volume%20of%20aif%20files" id="wpa2a_6"><img src="http://blog.indieiphonedev.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.indieiphonedev.com/2011/01/15/how-to-batch-change-volume-of-aif-files/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Getting the timezone on the device</title>
		<link>http://blog.indieiphonedev.com/2011/01/09/getting-the-timezone-on-the-device/</link>
		<comments>http://blog.indieiphonedev.com/2011/01/09/getting-the-timezone-on-the-device/#comments</comments>
		<pubDate>Sun, 09 Jan 2011 20:02:41 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[cocoa]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[iPhone app]]></category>
		<category><![CDATA[objective-C]]></category>
		<category><![CDATA[source code]]></category>
		<category><![CDATA[timezone]]></category>

		<guid isPermaLink="false">http://blog.indieiphonedev.com/?p=258</guid>
		<description><![CDATA[Since the LogYourRun iPhone application will show you your running data in week and month views it is necessary to know the timezone of the user in order to bring up the data for the correct week/month. At first I thought I could use the NSDateFormatter to do this. The documentation says that you can [...]]]></description>
			<content:encoded><![CDATA[<p>Since the LogYourRun iPhone application will show you your running data in week and month views it is necessary to know the timezone of the user in order to bring up the data for the correct week/month.  At first I thought I could use the NSDateFormatter to do this.  The documentation says that you can get timezone informationby using %z or %Z as the format.  The %z should get you the offset in hours while the %Z should get you the name.  However when tested it turned out that the opposite is the case&#8230; </p>
<p>The following code gets you the timezone offset in hours:</p>
<pre class="brush: objc; title: ; notranslate">
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@&quot;Z&quot;]; // error in documentation - the zone in hours should be 'z' not 'Z'
timezoneoffset = (int) [[dateFormatter stringFromDate:[NSDate date]] intValue]/100;
DLog(@&quot;format %@&quot;, [dateFormatter stringFromDate:[NSDate date]]);
[dateFormatter release];
</pre>
<p>(Note the division by 100 is because the timezone is reported in military time so for 30 min offset the final timezone would be read as x.30 which is not really correct &#8211; but for getting a ballpark figure it would suffice).</p>
<p>Since the code is not behaving according to documentation it is not a good idea to use this to get the timezone because the code will break if the code ever starts behaving according to documentation.  </p>
<p>Instead it turns out that there is a very nice NSTimeZone object which will give you the timezone offset from GMT in seconds:</p>
<pre class="brush: objc; title: ; notranslate">
int timezoneoffset = ([[NSTimeZone systemTimeZone] secondsFromGMT] / 3600);
</pre>
<p>Then all you have to do to get the hour difference is divide by 3600 (seconds per hour).  If you cared about the half hour offsets you would make this a float &#8211; but this is plenty for getting a ballpark figure.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.indieiphonedev.com%2F2011%2F01%2F09%2Fgetting-the-timezone-on-the-device%2F&amp;title=Getting%20the%20timezone%20on%20the%20device" id="wpa2a_8"><img src="http://blog.indieiphonedev.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.indieiphonedev.com/2011/01/09/getting-the-timezone-on-the-device/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MGTwitterEngine and Locations</title>
		<link>http://blog.indieiphonedev.com/2010/09/03/mgtwitterengine-and-locations/</link>
		<comments>http://blog.indieiphonedev.com/2010/09/03/mgtwitterengine-and-locations/#comments</comments>
		<pubDate>Sat, 04 Sep 2010 04:35:41 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[GPS]]></category>
		<category><![CDATA[iPhone app]]></category>
		<category><![CDATA[iPhone OS]]></category>
		<category><![CDATA[objective-C]]></category>
		<category><![CDATA[source code]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://blog.indieiphonedev.com/?p=212</guid>
		<description><![CDATA[How to implement location of tweets from iPhone applications using the MGTwitterEngine.]]></description>
			<content:encoded><![CDATA[<p>So Twitter just updated their API to disallow the use of authentication through the REST API.  They were nice enough to announce that in an email 2 days after they turned it off so that meant that I had to learn all about OAuth overnight and scramble to find something that could take over the Twitter functionality of the LogYourRun iPhone app.</p>
<p>Luckily most of the leg work in this are has been done by Matt Gemmell and his <a href="http://mattgemmell.com/2008/02/22/mgtwitterengine-twitter-from-cocoa">Twitter engine</a>.  Some slight modifications are required in order to get it <a href="http://github.com/bengottlieb/Twitter-OAuth-iPhone">running on the iPhone</a> and <a href="http://www.2bros1blog.com/2010/07/switching-from-basic-to-xauth-with-mgtwitterengine-on-iphone/">working with OAuth</a>.  Update:  The guys at iCodeBlog have a <a href="http://icodeblog.com/2010/09/16/dealing-with-the-twitter-oauth-apocalypse/">great tutorial</a> on how to implement the libraries.</p>
<p>With these libraries dropped in the new Twitter authentication system is fairly easy to implement.  The main problem is that the MGTwitterEngine does not support the Twitter location API.  Since this is an important piece of <a href="http://tweetmydistance.com/">TweetMyDistance</a> I modified the MGTwitterEngine.m and added a function for tweeting with location.  The new method takes latitude and longitude as well as the tweet and if this is a reply to a previous tweet.  As you can see from <a href="http://twitter.com/tim221175/statuses/22930742608">my tweet</a> it works great.  The code below should replace the code in MGTwitterEngine and don&#8217;t forget to also update your .h file.</p>
<pre class="brush: objc; title: ; notranslate">
- (NSString *)sendUpdate:(NSString *)status
{
    return [self sendUpdate:status inReplyTo:0];
}

- (NSString *)sendUpdate:(NSString *)status inReplyTo:(unsigned long)updateID
{

	return [self sendUpdate: status inReplyTo: updateID withLatitude: 0.0 andLongitude: 0.0];

}

- (NSString *)sendUpdate:(NSString *)status
			   inReplyTo:(unsigned long)updateID
			withLatitude:(double) lat
			andLongitude: (double) lng
{
	if (!status) {
        return nil;
    }

    NSString *path = [NSString stringWithFormat:@&quot;statuses/update.%@&quot;, API_FORMAT];

    NSString *trimmedText = status;
    if ([trimmedText length] &gt; MAX_MESSAGE_LENGTH) {
        trimmedText = [trimmedText substringToIndex:MAX_MESSAGE_LENGTH];
    }

    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
    [params setObject:trimmedText forKey:@&quot;status&quot;];
    if (updateID &gt; 0) {
        [params setObject:[NSString stringWithFormat:@&quot;%u&quot;, updateID] forKey:@&quot;in_reply_to_status_id&quot;];
    }
    if (lat != 0.0 &amp;&amp; lng != 0.0) {
		// lat=%1.6f&amp;long=%1.6f&amp;display_coordinates=true
        [params setObject:[NSString stringWithFormat:@&quot;%1.6f&quot;, lat] forKey:@&quot;lat&quot;];
        [params setObject:[NSString stringWithFormat:@&quot;%1.6f&quot;, lng] forKey:@&quot;long&quot;];
        [params setObject:@&quot;true&quot; forKey:@&quot;display_coordinates&quot;];
    }
    NSString *body = [self _queryStringWithBase:nil parameters:params prefixed:NO];

	DLog(@&quot; twitterbody: %@&quot;, body);

    return [self _sendRequestWithMethod:HTTP_POST_METHOD path:path
                        queryParameters:params body:body
                            requestType:MGTwitterUpdateSendRequest
                           responseType:MGTwitterStatus];
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.indieiphonedev.com/2010/09/03/mgtwitterengine-and-locations/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Converting App from iPhone to Universal</title>
		<link>http://blog.indieiphonedev.com/2010/04/29/converting-app-from-iphone-to-universal/</link>
		<comments>http://blog.indieiphonedev.com/2010/04/29/converting-app-from-iphone-to-universal/#comments</comments>
		<pubDate>Fri, 30 Apr 2010 03:54:47 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[iPad]]></category>
		<category><![CDATA[iPhone app]]></category>
		<category><![CDATA[objective-C]]></category>
		<category><![CDATA[source code]]></category>

		<guid isPermaLink="false">http://blog.indieiphonedev.com/?p=194</guid>
		<description><![CDATA[With the iPad selling like hot cakes it seems like a good idea to get on the bandwagon and make some apps for the iPad.  The LogYourRun app is not particularly well suited for running on the iPad &#8211; I doubt that people will be strapping their iPads to their arms and run around the [...]]]></description>
			<content:encoded><![CDATA[<p>With the iPad selling like hot cakes it seems like a good idea to get on the bandwagon and make some apps for the iPad.  The LogYourRun app is not particularly well suited for running on the iPad &#8211; I doubt that people will be strapping their iPads to their arms and run around the park.  However, the heart rate app seems like something that people would enjoy using even on iPads.  Since I did not want to have to maintain two separate apps I decided to make the app universal.  This was actually quite an easy process and took only about 10-12 hours (could have been faster if I had known what I was doing &#8211; which is why I wanted to share what I learned).</p>
<p>First step is to make sure you copy your application folder so you will be able to go back to the original application if you mess up.  Then with your newly copied application upgrade your target to work on the iPad in addition to the iPhone.  Click on your target and go into the menu &#8211; under Project you will find an entry that says &#8220;upgrade current target for iPad&#8221;.  Select the &#8220;One Universal application&#8221; option.  This will generate a new group which contains your new iPad version of the MainWindow.xib file &#8211; MainWindow-iPad.xib.  You can use this new nib to load all your iPad specific views.</p>
<p>At this point I went through all my existing nibs and created iPad versions (can be done in the Interface Builder) and saved them as XxxViewController-iPad.xib in the Resources-iPad folder.  For iPad nibs you have to make sure that you have versions of the nib that look decent and are usable in both landscape and horizontal orientations.  This can be tricky if you have a lot of UI elements but is very important since iPad apps have to support all orientations.  Make sure you anchor your UI elements to the right edges and that they scale to look nice.</p>
<p>The heart rate app uses a tab bar.  It took me the longest time to figure out how to get this to rotate.  The reason for this was that I had not read <a href="http://developer.apple.com/iphone/library/featuredarticles/ViewControllerPGforiPhoneOS/TabBarControllers/TabBarControllers.html#//apple_ref/doc/uid/TP40007457-CH102-SW26" target="_blank">Apple&#8217;s documentation</a>.  Turns out that <strong>all</strong> the view controllers that the tab bar links to have to return YES for all shouldAutorotateToInterfaceOrientation: orientations.  This makes sense conceptually.  In addition you need to <a href="http://blog.costan.us/2009/01/auto-rotating-tab-bars-on-iphone.html">set your view controllers</a> to automatically resize when rotation occurs.  Once these are set you will be able to see what the rotation looks like in the iPad simulator (hopefully great).</p>
<p>Loading the iPad specific nibs using the view controller is a great way to get these to show up on the iPad only &#8211; but there are some cases where you will need to load a view controller programatically (in my case when the user clicks on the help button it brings up the help VC).  To make sure that you load the right nib you can check if the app is running on the iPad.  The following code is what I used:</p>
<pre>
<pre class="brush: objc; title: ; notranslate">
- (BOOL) isIPad {
#if (__IPHONE_OS_VERSION_MAX_ALLOWED &gt;= 30200)
  if ([[UIDevice currentDevice] respondsToSelector: @selector(userInterfaceIdiom)])
    return ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad);
#endif

  return NO;
}
</pre>
</pre>
<p>This code will check if the iDevice responds to the userInterfaceIdiom selector and if it does it checks if the device is an iPad.  If it is I load the iPad version of the helpVC if not then I load the iPhone version of the helpVC.  Make sure you also put the respondToRotation in these VCs since they will need to respond predictably also.</p>
<p>Finally you will need to create a default image that can be presented on the iPhone.  In your info.plist you can set the &#8220;Launch image (iPad)&#8221; to the base name of the iPad graphic (e.g. Default-iPad.png).  You can then create two images named Default-iPad-Landscape and Default-iPad-Portrait and add them to your project.  The iPad will pick whichever of the default images that fits with the rotation of the device.</p>
<p>When uploading your app &#8211; build the app in OS3.2.  The app will run on both iPhone and iPad from one binary. You will also have to upload screenshots for the iPad version for display in the iPad app store and create two new icons (50&#215;50 and 72&#215;72).  Once you have all that together your app is ready for submission and you can start praying that it will be a speedy path to acceptance.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.indieiphonedev.com%2F2010%2F04%2F29%2Fconverting-app-from-iphone-to-universal%2F&amp;title=Converting%20App%20from%20iPhone%20to%20Universal" id="wpa2a_10"><img src="http://blog.indieiphonedev.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.indieiphonedev.com/2010/04/29/converting-app-from-iphone-to-universal/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Elevation for routes</title>
		<link>http://blog.indieiphonedev.com/2010/04/09/elevation-for-routes/</link>
		<comments>http://blog.indieiphonedev.com/2010/04/09/elevation-for-routes/#comments</comments>
		<pubDate>Sat, 10 Apr 2010 00:57:25 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[core location]]></category>
		<category><![CDATA[google maps]]></category>
		<category><![CDATA[GPS]]></category>
		<category><![CDATA[iPhone app]]></category>

		<guid isPermaLink="false">http://blog.indieiphonedev.com/?p=173</guid>
		<description><![CDATA[I have been playing around with the GPS functionality of the iPhone for a while now and I think I have optimized the collection of in-plane GPS data as best as possible given the limitations of the hardware.  The iPhone was not created to be a garmin forerunner and this especially shines through when you [...]]]></description>
			<content:encoded><![CDATA[<p>I have been playing around with the GPS functionality of the iPhone for a while now and I think I have optimized the collection of in-plane GPS data as best as possible given the limitations of the hardware.  The iPhone was not created to be a garmin forerunner and this especially shines through when you try to get elevation data out of the iPhone GPS.  This became painfully obvious after I built the functionality for collecting and displaying elevation data from the GPS.  Even after creating sophisticated methods for filtering the GPS data and averaging the data and weighing the data by the vertical accuracy the graphs of the running data had no correlation with reality.  At first this was disappointing &#8211; I had created this great code for collecting, saving, and displaying the elevation data but clearly if I released an app which was going to show unrealistic elevation data &#8211; the app would get killed by bad reviews.</p>
<p>So I looked around for other places to get elevation data.  Turns out that the space station has used lasers to measure elevation all over the surface of the earth and that Google has an API which allows you to query that data.  This means much better resolution on the elevation data than a GPS (even a garmin) could ever provide and I can show elevation data for both current routes as well as routes that have been saved which have no elevation data saved with them.  The only issue is that a data connection is required in order to get at this data but the amount of data being sent back and forth is so small that the elevation data shows up almost instantly even on an EDGE connection.  Being a good citizen I only have the app request elevation data if the user is interested in seeing this type of data &#8211; this keeps data usage down and keeps load off Google&#8217;s servers.</p>
<p>The video below shows how the elevation data is displayed within the app.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="480" height="385" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/UzgwUBM23ww&amp;hl=en_US&amp;fs=1&amp;" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="480" height="385" src="http://www.youtube.com/v/UzgwUBM23ww&amp;hl=en_US&amp;fs=1&amp;" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.indieiphonedev.com%2F2010%2F04%2F09%2Felevation-for-routes%2F&amp;title=Elevation%20for%20routes" id="wpa2a_12"><img src="http://blog.indieiphonedev.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.indieiphonedev.com/2010/04/09/elevation-for-routes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using audio services to play alert sound</title>
		<link>http://blog.indieiphonedev.com/2010/03/22/using-audio-services-to-play-alert-sound/</link>
		<comments>http://blog.indieiphonedev.com/2010/03/22/using-audio-services-to-play-alert-sound/#comments</comments>
		<pubDate>Tue, 23 Mar 2010 04:24:36 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[cocoa]]></category>
		<category><![CDATA[iPhone app]]></category>
		<category><![CDATA[objective-C]]></category>
		<category><![CDATA[sounds]]></category>
		<category><![CDATA[source code]]></category>

		<guid isPermaLink="false">http://blog.indieiphonedev.com/?p=150</guid>
		<description><![CDATA[Some times it your application may inadvertently quit with out the user meaning to quit your app.  For example people run with the running/GPS app and the iPhone may be in a pocket / arm band / hand where the square button could be pressed unintentionally.  If the app quits while running it will not [...]]]></description>
			<content:encoded><![CDATA[<p>Some times it your application may inadvertently quit with out the user meaning to quit your app.  For example people run with the running/GPS app and the iPhone may be in a pocket / arm band / hand where the square button could be pressed unintentionally.  If the app quits while running it will not collect running data for the rest of the run and the user will be very disappointed.  To avoid this I have setup an alert which will make a sound if the user quits the app while the app is collecting running data.  I was able to find the original apple alert aiff files via Google and I chose to implement the Indigo sound as the alert &#8211; the cricket is not really loud enough to be an alert sound.</p>
<p>By implementing the playback of the sound as an alert sound the sound will be played even on the 1st gen iPod Touch which does not have a speaker.  Alert sounds can also be set to finish playback after the app finishes &#8211; which is an important feature for this use.  I was able to find how to set this property on <a href="http://nagano.monalisa-au.org/?p=721">Nagano&#8217;s blog</a>.  Not sure what most of the page says but the language of Objective C is universal. Remember to add the audiotoolbox to your project.</p>
<pre class="brush: objc; title: ; notranslate">

#include &amp;lt;AudioToolbox/AudioToolbox.h&amp;gt;
</pre>
<p>I then load the sound in the viewDidLoad init function for the view controller where I want to play the sound &#8211; this way you are not trying to load the sound as the app is quitting.  The soundFileObject isa global for this VC.</p>
<pre class="brush: objc; title: ; notranslate">
// SOUNDS
 NSString *path = [[NSBundle mainBundle] pathForResource:@&amp;quot;Indigo&amp;quot; ofType:@&amp;quot;aiff&amp;quot;];
 NSURL *fileURL = [NSURL fileURLWithPath:path];

 OSStatus err;
 err = AudioServicesCreateSystemSoundID((CFURLRef)fileURL, &amp;amp;soundFileObject);
 if(err) {
   DLog(@&amp;quot;AudioServicesCreateSystemSoundID err = %d&amp;quot;,err);
   exit(1);
 }

 UInt32 flag = 1;
 err = AudioServicesSetProperty(kAudioServicesPropertyCompletePlaybackIfAppDies,
     sizeof(UInt32),
     &amp;amp;soundFileObject,
     sizeof(UInt32),
     &amp;amp;flag);
 if(err){
   DLog(@&amp;quot;AudioServicesSetProperty err = %d&amp;quot;,err);
 }
</pre>
<p>Then under viewWillDisappear I have the following:</p>
<pre class="brush: objc; title: ; notranslate">
 if (runActivity.isStarted) {
   // play alert sound if exiting while running
   AudioServicesPlayAlertSound (self.soundFileObject);
 }
</pre>
<p>This way the sound will play if the view is unloading while the user is expecting the app to be collecting data.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.indieiphonedev.com%2F2010%2F03%2F22%2Fusing-audio-services-to-play-alert-sound%2F&amp;title=Using%20audio%20services%20to%20play%20alert%20sound" id="wpa2a_14"><img src="http://blog.indieiphonedev.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.indieiphonedev.com/2010/03/22/using-audio-services-to-play-alert-sound/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WebKitErrorDomain error 101</title>
		<link>http://blog.indieiphonedev.com/2010/02/19/webkiterrordomain-101/</link>
		<comments>http://blog.indieiphonedev.com/2010/02/19/webkiterrordomain-101/#comments</comments>
		<pubDate>Sat, 20 Feb 2010 00:48:21 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[cocoa]]></category>
		<category><![CDATA[error code]]></category>
		<category><![CDATA[iPhone app]]></category>
		<category><![CDATA[objective-C]]></category>
		<category><![CDATA[source code]]></category>

		<guid isPermaLink="false">http://blog.indieiphonedev.com/?p=136</guid>
		<description><![CDATA[The LogYourRun app uses both UIWebView and NSURLRequest to communicate with the LogYourRun database.  To let users upload and access their data.  These requests often contain fields that the user enter such as running notes, distance, time etc.  I had the WebKitErrorDomain 101 error come up on occasions when users tried to send requests that [...]]]></description>
			<content:encoded><![CDATA[<p>The LogYourRun app uses both UIWebView and NSURLRequest to communicate with the LogYourRun database.  To let users upload and access their data.  These requests often contain fields that the user enter such as running notes, distance, time etc.  I had the WebKitErrorDomain 101 error come up on occasions when users tried to send requests that contained spaces that were not properly encoded.  I was not able to find any documentation on this error so it took a while to figure out what was going on.</p>
<div id="attachment_137" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.indieiphonedev.com/wp-content/uploads/2010/02/webkiterror.png"><img class="size-medium wp-image-137" title="webkiterror" src="http://blog.indieiphonedev.com/wp-content/uploads/2010/02/webkiterror-300x172.png" alt="" width="300" height="172" /></a><p class="wp-caption-text">WebKitErrorDomain error 101</p></div>
<p>Once I identified that the issue was that some users had a space in their username it is a very easy fix.  Just use the stringByAddingPercentEscapesUsingEncoding function to have the string properly encoded:</p>
<pre class="brush: objc; title: ; notranslate">
[username stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding];
</pre>
<p>So if you come along a WebKitErrorDomain 101 error &#8211; take a look at the URL you are trying to submit and see if all the parts of it are properly encoded.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.indieiphonedev.com%2F2010%2F02%2F19%2Fwebkiterrordomain-101%2F&amp;title=WebKitErrorDomain%20error%20101" id="wpa2a_16"><img src="http://blog.indieiphonedev.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.indieiphonedev.com/2010/02/19/webkiterrordomain-101/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to test location and accelerometer functions from the comfort of your home</title>
		<link>http://blog.indieiphonedev.com/2010/02/07/how-to-test-location-and-accelerometer-functions-from-the-comfort-of-your-home/</link>
		<comments>http://blog.indieiphonedev.com/2010/02/07/how-to-test-location-and-accelerometer-functions-from-the-comfort-of-your-home/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 03:01:11 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[accelerometer]]></category>
		<category><![CDATA[core location]]></category>
		<category><![CDATA[google maps]]></category>
		<category><![CDATA[iPhone app]]></category>
		<category><![CDATA[objective-C]]></category>
		<category><![CDATA[source code]]></category>

		<guid isPermaLink="false">http://blog.indieiphonedev.com/?p=123</guid>
		<description><![CDATA[The LogYourRun iPhone app uses both the GPS and the accelerometer functions of the iPhone.  Neither the GPS nor the accelerometer can be accessed on the iPhone simulator so to circumvent this I used the following methods: Accelerometer: Otto Chrons has a great Google code project which contains the code for an app that can [...]]]></description>
			<content:encoded><![CDATA[<p>The LogYourRun iPhone app uses both the GPS and the accelerometer functions of the iPhone.  Neither the GPS nor the accelerometer can be accessed on the iPhone simulator so to circumvent this I used the following methods:</p>
<p><strong>Accelerometer: </strong> Otto Chrons has a great <a href="http://code.google.com/p/accelerometer-simulator/wiki/Home" target="_blank">Google code project</a> which contains the code for an app that can be run on an iPod touch or iPhone which is on the same subnet as your development computer.  The app will transmit accelerometer data which can be caught by some code that you can insert into your Xcode project.  When you run your app on the iPhone simulator it will thus receive the accelerometer data from the real life device.  This was a great help in troubleshooting the setup of the pedometer functionality.  I was running around in my living room counting steps and comparing to the # of steps on the iPhone simulator.  Be sure to remove the accelerometer simulator code from your application before releasing.</p>
<p><strong>GPS:</strong> Everyone who has played with the location manager on the iPhone Simulator knows that you will only get only one location from the location manager on the iPhone Simulator.  Testing the GPS functionality is a critical part of testing the LogYourRun app.  I could run the app on an iPhone and then run/walk/drive around outside &#8211; but that would take much too long and the weather in Saint Louis is not conductive to such testing.  Instead I added a button to the pedometer screen of the application which when clicked runs the following code:</p>
<pre class="brush: objc; title: ; notranslate">
- (IBAction) locationButton:(id)sender {
   CLLocation *thisLocation;
   double latitude  = 37.33168900 + (float) ((random() % 100) +1) / 1000000.0;
   double longitude = -122.03073100 + (float) ((random() % 100) +1) / 1000000.0;
   thisLocation = [[CLLocation alloc] initWithLatitude:latitude longitude:longitude];
   [self locationManager:locationManager didUpdateToLocation:thisLocation fromLocation:thisLocation];
   [thisLocation release];
}</pre>
<p>This piece of code creates a random location close to the location that the iPhone Simulator will usually get from the core location (One Infinite Loop).  The location is sent to the location manager delegate function of the pedometer class and is handled as if it came from the real location manager.  Since the location is different from the previous location the getDistanceFrom: still works.  When I am ready to submit the application all I have to do is hide the two buttons (probably should be done programatically &#8211; since one of these days I will forget).</p>
<div id="attachment_122" class="wp-caption aligncenter" style="width: 210px"><a href="http://blog.indieiphonedev.com/wp-content/uploads/2010/02/Screenshot.png"><img class="size-medium wp-image-122" title="Pedometer showing location and step button" src="http://blog.indieiphonedev.com/wp-content/uploads/2010/02/Screenshot-200x300.png" alt="Pedometer showing location and step button" width="200" height="300" /></a><p class="wp-caption-text">The pedometer screen showing location and step button</p></div>
<p style="text-align: center;">
<div id="attachment_127" class="wp-caption aligncenter" style="width: 210px"><a href="http://blog.indieiphonedev.com/wp-content/uploads/2010/02/Screenshot-2010.02.07-21.45.30.png"><img class="size-medium wp-image-127" title="Locations shown on map" src="http://blog.indieiphonedev.com/wp-content/uploads/2010/02/Screenshot-2010.02.07-21.45.30-200x300.png" alt="Locations shown on map" width="200" height="300" /></a><p class="wp-caption-text">The random locations shown on map</p></div>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.indieiphonedev.com%2F2010%2F02%2F07%2Fhow-to-test-location-and-accelerometer-functions-from-the-comfort-of-your-home%2F&amp;title=How%20to%20test%20location%20and%20accelerometer%20functions%20from%20the%20comfort%20of%20your%20home" id="wpa2a_18"><img src="http://blog.indieiphonedev.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.indieiphonedev.com/2010/02/07/how-to-test-location-and-accelerometer-functions-from-the-comfort-of-your-home/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

