<?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>Scott Gruby&#039;s Blog &#187; Programming</title> <atom:link href="http://blog.gruby.com/tag/programming/feed/" rel="self" type="application/rss+xml" /><link>http://blog.gruby.com</link> <description>Another semi-useless spot on the web...</description> <lastBuildDate>Fri, 23 Dec 2011 05:23:22 +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>Working with blocks</title><link>http://blog.gruby.com/2011/11/13/working-with-blocks/</link> <comments>http://blog.gruby.com/2011/11/13/working-with-blocks/#comments</comments> <pubDate>Mon, 14 Nov 2011 05:22:00 +0000</pubDate> <dc:creator>Scott Gruby</dc:creator> <category><![CDATA[Main]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Software]]></category><guid isPermaLink="false">https://blog.gruby.com/?p=3182</guid> <description><![CDATA[In Mac OS X 10.6 and iOS 4, Apple added blocks to Objective-C. When I first started looking at them because various APIs used them, the syntax confused me, and I pretty much ignored them as I was still doing &#8230; <a href="http://blog.gruby.com/2011/11/13/working-with-blocks/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>In Mac OS X 10.6 and iOS 4, Apple added <a href="http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/Blocks/Articles/00_Introduction.html">blocks</a> to Objective-C. When I first started looking at them because various APIs used them, the syntax confused me, and I pretty much ignored them as I was still doing work that ran on iOS 4 and Mac OS X 10.5.</p><p>This spring, all my projects moved to iOS 4 and Mac OS X 10.6 as the minimum requirements, so I took another pass at learning blocks. This time, however, I could actually use them and read all I could about them. The more I started looking at them, the more I became enamored with them. I started using blocks in my own APIs and just finished rewriting a significant chunk of code using blocks. Using blocks has made my code more readable and has greatly simplified certain aspects of our app.</p><p>One of my co-workers cautioned me to not use blocks just because they were the shiny new tool which I admit was what I was looking at doing. However, after using them, we found that using blocks was pretty much vital to making our code more readable.</p><p>For developers that aren&#8217;t familiar with blocks, I&#8217;d suggest learning them. With most iOS apps having a minimum OS of 4.0, there is no reason to avoid them.<br /><hr/>Copyright &copy; 2012 <strong><a href="http://blog.gruby.com">Scott Gruby</a></strong>. The opinions expressed here do not necessarily reflect those of my employer. Please visit this site and use the Amazon link to support it.</p> ]]></content:encoded> <wfw:commentRss>http://blog.gruby.com/2011/11/13/working-with-blocks/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>The end of MovieConverter</title><link>http://blog.gruby.com/2011/10/16/the-end-of-movieconverter/</link> <comments>http://blog.gruby.com/2011/10/16/the-end-of-movieconverter/#comments</comments> <pubDate>Mon, 17 Oct 2011 02:52:51 +0000</pubDate> <dc:creator>Scott Gruby</dc:creator> <category><![CDATA[Main]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Software]]></category> <category><![CDATA[Technology]]></category><guid isPermaLink="false">https://blog.gruby.com/?p=3147</guid> <description><![CDATA[It was just over 2 months ago when I released MovieConverter to the world to fill a gap where iMovie for iPad wouldn&#8217;t import videos from certain video cameras including my Sony Cyber-Shot DSC-WX9. I had originally came up with &#8230; <a href="http://blog.gruby.com/2011/10/16/the-end-of-movieconverter/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>It was just over 2 months ago when I released MovieConverter to the world to fill a gap where iMovie for iPad wouldn&#8217;t import videos from certain video cameras including my <a href="http://www.amazon.com/gp/product/B004H8FNJY/ref=as_li_ss_tl?ie=UTF8&#038;tag=grubyblog-20&#038;linkCode=as2&#038;camp=217145&#038;creative=399373&#038;creativeASIN=B004H8FNJY">Sony Cyber-Shot DSC-WX9</a><img src="http://www.assoc-amazon.com/e/ir?t=grubyblog-20&#038;l=as2&#038;o=1&#038;a=B004H8FNJY&#038;camp=217145&#038;creative=399373" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />. I had originally came up with the idea for MovieConverter back when I got my iPad 2 and started playing with iMovie. I worked on MovieConverter over the summer and finally released it.</p><p>When I installed iOS 5 on my iPad 2, I found that iMovie imported more videos than before, but still not ones from my WX9. I made a few minor updates to MovieConverter to get it working better on iOS 5 and pushed it out the door. I got back from vacation the day after iOS 5 got released to the public and quickly updated everything including iMovie. The iMovie 1.2.2 notes said it added support for importing video from additional cameras.</p><p>Much to my delight and dismay, the videos from my WX9 imported into iMovie without MovieConverter. I immediately updated the MovieConverter description to say it may longer be needed and dropped the price to free so that no users would be pissed at me for writing a &#8220;useless&#8221; program.</p><p>From an iMovie user point of view, this is great news. I didn&#8217;t write MovieConverter for fame or fortune, but it was nice to get a little money from it.</p><p>Oh well, now I have to come up with another idea that will have a little more than 2 months on the app store.<br /><hr/>Copyright &copy; 2012 <strong><a href="http://blog.gruby.com">Scott Gruby</a></strong>. The opinions expressed here do not necessarily reflect those of my employer. Please visit this site and use the Amazon link to support it.</p> ]]></content:encoded> <wfw:commentRss>http://blog.gruby.com/2011/10/16/the-end-of-movieconverter/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>MovieConverter available on the App Store</title><link>http://blog.gruby.com/2011/08/02/movieconverter-available-on-the-app-store/</link> <comments>http://blog.gruby.com/2011/08/02/movieconverter-available-on-the-app-store/#comments</comments> <pubDate>Tue, 02 Aug 2011 22:55:13 +0000</pubDate> <dc:creator>Scott Gruby</dc:creator> <category><![CDATA[Main]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Software]]></category> <category><![CDATA[Technology]]></category><guid isPermaLink="false">https://blog.gruby.com/?p=3051</guid> <description><![CDATA[I&#8217;m pleased to announce that my MovieConverter app is now available on the iOS App Store. The app is designed for iPad users that want to import and edit video that was taken with a compact digital camera in iMovie. &#8230; <a href="http://blog.gruby.com/2011/08/02/movieconverter-available-on-the-app-store/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>I&#8217;m pleased to announce that my <a href="http://itunes.apple.com/us/app/movieconverter/id452918598?mt=8">MovieConverter</a> app is now available on the iOS App Store. The app is designed for iPad users that want to import and edit video that was taken with a compact digital camera in iMovie.</p><p>The premise is pretty simple, but I think it is a huge help to those that don&#8217;t want to travel with a laptop and want to edit video.</p><p>While I don&#8217;t expect to become a millionaire on this, I do hope to sell enough copies to go out to dinner a few times!</p><p>Thanks Apple for the fast turnaround on approving this! Total time less than 9 calendar days from initial submission.<br /><hr/>Copyright &copy; 2012 <strong><a href="http://blog.gruby.com">Scott Gruby</a></strong>. The opinions expressed here do not necessarily reflect those of my employer. Please visit this site and use the Amazon link to support it.</p> ]]></content:encoded> <wfw:commentRss>http://blog.gruby.com/2011/08/02/movieconverter-available-on-the-app-store/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Another Lion change wreaking havoc</title><link>http://blog.gruby.com/2011/07/24/another-lion-change-wreaking-havoc/</link> <comments>http://blog.gruby.com/2011/07/24/another-lion-change-wreaking-havoc/#comments</comments> <pubDate>Mon, 25 Jul 2011 04:27:47 +0000</pubDate> <dc:creator>Scott Gruby</dc:creator> <category><![CDATA[Main]]></category> <category><![CDATA[Programming]]></category><guid isPermaLink="false">https://blog.gruby.com/?p=3047</guid> <description><![CDATA[One common practice when subclassing a class is to use an application specific prefix so that if Apple adds a similar class in the future, it doesn&#8217;t conflict. For ReceiptWallet, I always used RW. One of the classes I subclassed &#8230; <a href="http://blog.gruby.com/2011/07/24/another-lion-change-wreaking-havoc/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>One common practice when subclassing a class is to use an application specific prefix so that if Apple adds a similar class in the future, it doesn&#8217;t conflict. For ReceiptWallet, I always used RW. One of the classes I subclassed was NSTextView so that I could draw text in gray when no text is entered. This is similar to NSTextFieldCell&#8217;s setPlaceHolderString method. I named my member variable placeHolderString and added a property. The code worked fine on Snow Leopard, but when it was run on Lion, we had reports that the placeholder text was drawn twice and blurry.</p><p>It appears that Apple added this property to NSTextView in Lion, but didn&#8217;t document it. I tried lots of different tactics to fix it, but decided the easiest thing to do was to rename my member variable/property. That worked perfectly and remains backwardly compatible.</p><p>So despite my best effort to keep my changes in my own namespace, there was no way for me to anticipate or detect this kind of change.</p><p>Lesson learned.<br /><hr/>Copyright &copy; 2012 <strong><a href="http://blog.gruby.com">Scott Gruby</a></strong>. The opinions expressed here do not necessarily reflect those of my employer. Please visit this site and use the Amazon link to support it.</p> ]]></content:encoded> <wfw:commentRss>http://blog.gruby.com/2011/07/24/another-lion-change-wreaking-havoc/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Bit by API Changes</title><link>http://blog.gruby.com/2011/07/23/bit-by-api-changes/</link> <comments>http://blog.gruby.com/2011/07/23/bit-by-api-changes/#comments</comments> <pubDate>Sun, 24 Jul 2011 03:54:34 +0000</pubDate> <dc:creator>Scott Gruby</dc:creator> <category><![CDATA[Main]]></category> <category><![CDATA[Programming]]></category><guid isPermaLink="false">https://blog.gruby.com/?p=3045</guid> <description><![CDATA[Mac OS X Lion has changed some of the internal workings of various APIs and as I don&#8217;t work much on Mac apps, I didn&#8217;t care too much. However, one app I work on got bit by this pretty hard. &#8230; <a href="http://blog.gruby.com/2011/07/23/bit-by-api-changes/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>Mac OS X Lion has changed some of the internal workings of various APIs and as I don&#8217;t work much on Mac apps, I didn&#8217;t care too much. However, one app I work on got bit by this pretty hard. In various places in the NSDocument based app, I called:</p><pre class="brush: objc;">
[self saveDocument:self];
</pre><p>This, I had assumed, was a synchronous call and then proceeded to make calls after that based on the fact that the call succeeded. Up until OS X Lion, things seemed to work fine. However, with Lion, this call seemed to cause problems and after reading the header file for NSDocument, I instantly realized the issue:</p><pre>
/* The action of the File menu's Save item in a document-based application. The default implementation of this method merely invokes [self saveDocumentWithDelegate:nil didSaveSelector:NULL contextInfo:NULL].
*/
- (IBAction)saveDocument:(id)sender;
</pre><p>So I was tricked into thinking there was a synchronous call and got bit by it. So I&#8217;ve fixed the code to use a callback and things seem to be working better. While I should have been using the asynchronous call all along, I don&#8217;t recall if it existed in OS X 10.4 when I first wrote the program.<br /><hr/>Copyright &copy; 2012 <strong><a href="http://blog.gruby.com">Scott Gruby</a></strong>. The opinions expressed here do not necessarily reflect those of my employer. Please visit this site and use the Amazon link to support it.</p> ]]></content:encoded> <wfw:commentRss>http://blog.gruby.com/2011/07/23/bit-by-api-changes/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Unit testing framework and Asynchronous calls</title><link>http://blog.gruby.com/2011/06/25/unit-testing-framework-and-asynchronous-calls/</link> <comments>http://blog.gruby.com/2011/06/25/unit-testing-framework-and-asynchronous-calls/#comments</comments> <pubDate>Sun, 26 Jun 2011 03:37:41 +0000</pubDate> <dc:creator>Scott Gruby</dc:creator> <category><![CDATA[Main]]></category> <category><![CDATA[Programming]]></category><guid isPermaLink="false">https://blog.gruby.com/?p=3017</guid> <description><![CDATA[In my quest for information on writing test cases within the confines of unit testing framework, it became evident quite quickly that the tests are synchronous and asynchronous calls will never complete thereby rendering the test case useless. Since all &#8230; <a href="http://blog.gruby.com/2011/06/25/unit-testing-framework-and-asynchronous-calls/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>In my quest for information on writing test cases within the confines of unit testing framework, it became evident quite quickly that the tests are synchronous and asynchronous calls will never complete thereby rendering the test case useless. Since all networking code should be asynchronous (in my expert opinion), I had to find a way to handle this.</p><p>After a few quick searches, I found that my issue wasn&#8217;t uncommon. The most straightforward answer to this question is some code called <a href="https://gist.github.com/506353/">AssertEventually</a> by a developer named <a href="http://lukeredpath.co.uk/">Luke Redpath</a>. Straightforward in that the calling method is not complex; however, there is a big chunk of code behind it that has me a little concerned.</p><p>The more I&#8217;ve read about this, the more it looks like I have to spin my own run loop during the test such as <a href="http://www.cocoabuilder.com/archive/xcode/247124-asynchronous-unit-testing.html">described</a> on a mailing list like this:</p><pre>
while (!_isDone)
{
	[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
}</pre><p>While this should work, it isn&#8217;t the most efficient way to do things, but at this point, I&#8217;m not sure there are other options.<br /><hr/>Copyright &copy; 2012 <strong><a href="http://blog.gruby.com">Scott Gruby</a></strong>. The opinions expressed here do not necessarily reflect those of my employer. Please visit this site and use the Amazon link to support it.</p> ]]></content:encoded> <wfw:commentRss>http://blog.gruby.com/2011/06/25/unit-testing-framework-and-asynchronous-calls/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Utility of Unit Tests in software development</title><link>http://blog.gruby.com/2011/06/24/utility-of-unit-tests-in-software-development/</link> <comments>http://blog.gruby.com/2011/06/24/utility-of-unit-tests-in-software-development/#comments</comments> <pubDate>Sat, 25 Jun 2011 03:29:02 +0000</pubDate> <dc:creator>Scott Gruby</dc:creator> <category><![CDATA[Main]]></category> <category><![CDATA[Programming]]></category><guid isPermaLink="false">https://blog.gruby.com/?p=3014</guid> <description><![CDATA[Over the years, I&#8217;ve read a little about unit testing and heard it talked about at WWDC once or twice, but never thought much of it and didn&#8217;t see much of a need for it. Recently I&#8217;ve started to look &#8230; <a href="http://blog.gruby.com/2011/06/24/utility-of-unit-tests-in-software-development/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>Over the years, I&#8217;ve read a little about unit testing and heard it talked about at WWDC once or twice, but never thought much of it and didn&#8217;t see much of a need for it. Recently I&#8217;ve started to look at it again and have done a little research on the concept. I found a <a href="http://www.artima.com/weblogs/viewpost.jsp?thread=126923">reference</a> that seems to sum up the flaws of unit tests.</p><blockquote><p>A test is not a unit test if:</p><p>It talks to the database<br /> It communicates across the network<br /> It touches the file system<br /> It can&#8217;t run at the same time as any of your other unit tests<br /> You have to do special things to your environment (such as editing config files) to run it.</p></blockquote><p>Of all the projects I&#8217;ve worked on over the years, most, if not all, of them have had external dependencies such as network connections, handheld devices, or files on disk and therefore most of the unit tests I&#8217;d write adhering to the above rules, would barely exercise the app. If I wrote unit tests to simulate networks, I&#8217;d have to hard code in test data which lets us test one path in our app if we assume the data on the network never changes which is quite unlikely.</p><p>So, effectively unit tests are useless. I&#8217;m sure that someone will argue with me about this point, but if we assume I&#8217;m correct in the limited utility of unit tests, can tests be written that are useful?</p><p>Of course, we can write tests using the unit test framework (like <a href="http://developer.apple.com/tools/unittest.html">OCUnit</a> in Xcode 4). The test aren&#8217;t unit tests, they&#8217;re more like functional or integration tests that have external dependencies. This will let us test error conditions and see how different parts of the code will act in a real world environment.</p><p>It appears that Wil Shipley of Delicious Library fame seems to have similar <a href="http://wilshipley.com/blog/2005/09/unit-testing-is-teh-suck-urr.html">views</a> to me on this topic. However, I&#8217;m not opposed to functional or integration tests.</p><p>I don&#8217;t discount the utility of writing &#8220;tests&#8221; and will be writing some to test chunks of my code, but for the projects I&#8217;ve been on and expect to be on, unit tests have very limited utility and are possibly a poor use of limited resources.<br /><hr/>Copyright &copy; 2012 <strong><a href="http://blog.gruby.com">Scott Gruby</a></strong>. The opinions expressed here do not necessarily reflect those of my employer. Please visit this site and use the Amazon link to support it.</p> ]]></content:encoded> <wfw:commentRss>http://blog.gruby.com/2011/06/24/utility-of-unit-tests-in-software-development/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Another WWDC</title><link>http://blog.gruby.com/2011/06/09/another-wwdc/</link> <comments>http://blog.gruby.com/2011/06/09/another-wwdc/#comments</comments> <pubDate>Fri, 10 Jun 2011 04:26:19 +0000</pubDate> <dc:creator>Scott Gruby</dc:creator> <category><![CDATA[Main]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Technology]]></category><guid isPermaLink="false">https://blog.gruby.com/?p=2997</guid> <description><![CDATA[This week, I had the opportunity to attend Apple&#8217;s Worldwide Developers Conference (WWDC). I&#8217;ve been to a number of other WWDCs with the last one being in 2008. Things have changed significantly in the past years as the popularity of &#8230; <a href="http://blog.gruby.com/2011/06/09/another-wwdc/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>This week, I had the opportunity to attend Apple&#8217;s Worldwide Developers Conference (WWDC). I&#8217;ve been to a number of other WWDCs with the last one being in 2008. Things have changed significantly in the past years as the popularity of iOS (iPhone and iPad OS) increases. Unfortunately, I don&#8217;t think that the changes are for the better.</p><p>I&#8217;ve been writing handheld software for almost 17 years and been writing Objective-C software for around 10 years which now makes me one of the old timers in this game. In order for Apple to cater to everyone (all 5200 attendees), they have had to dumb down many of the sessions. In addition as indicated in the keynote, WWDC was going to cover Lion, iOS 5 and iCloud. With iOS 5 being released in the fall, it will be a long time before I actually get to use features in iOS 5, so I&#8217;ve sat through many sessions containing information about stuff I can&#8217;t use for awhile. Typically the apps I write can&#8217;t drop support for an operating system for about a year. (There are some cases where we can use newer features, but for the most part, we have to use the same features across all OS versions.) As my products are now requiring iOS 4, I can learn some of the information from last year&#8217;s conference.</p><p>WWDC has grown each year which caused it to sell out within hours this year. I was on top of things, so I was able to get a ticket. With all of these people clamoring to absorb all the informations they can, attendees end up waiting in lines for each and every session. This gets old quite quickly. Last year Apple put out the WWDC videos pretty soon after the conference and I hope they do that again this year; watching the videos may be as valuable, or even more valuable, then being at the conference.</p><p>The real value, for me, was hanging out with my co-workers and meeting other members of my group that I&#8217;ve only met by email. This, of course, is invaluable and there is really no substitute for it.</p><p>Will I be coming back next year? I&#8217;m not sure.<br /><hr/>Copyright &copy; 2012 <strong><a href="http://blog.gruby.com">Scott Gruby</a></strong>. The opinions expressed here do not necessarily reflect those of my employer. Please visit this site and use the Amazon link to support it.</p> ]]></content:encoded> <wfw:commentRss>http://blog.gruby.com/2011/06/09/another-wwdc/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>More pitfalls to synchronous networking</title><link>http://blog.gruby.com/2011/05/24/more-pitfalls-to-synchronous-networking/</link> <comments>http://blog.gruby.com/2011/05/24/more-pitfalls-to-synchronous-networking/#comments</comments> <pubDate>Wed, 25 May 2011 02:18:59 +0000</pubDate> <dc:creator>Scott Gruby</dc:creator> <category><![CDATA[Main]]></category> <category><![CDATA[Programming]]></category><guid isPermaLink="false">https://blog.gruby.com/?p=2992</guid> <description><![CDATA[Anyone that reads my blog or talks to me professionally knows how much I hate dislike asynchronous network programming. While working on rewriting some networking code, I came across a few more reasons why synchronous networking is a poor decision. &#8230; <a href="http://blog.gruby.com/2011/05/24/more-pitfalls-to-synchronous-networking/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>Anyone that reads my blog or talks to me professionally knows how much I hate dislike <a href="http://blog.gruby.com/2011/01/29/synchronous-vs-asynchronous-networking-programming/">asynchronous network programming</a>. While working on rewriting some networking code, I came across a few more reasons why synchronous networking is a poor decision.</p><p>The first issue occurs when a developer abstracts the networking, then forgets that when the call is invoked, it actually makes a network call and does it on the main thread. Synchronous networking should never be done on the main thread. For instance, let us use the following made up example:</p><pre class="brush: objc;">
- (void) displayUserPreferences
{
	Preferences *prefs = [[Utility sharedInstance] getPreferences];
	if (prefs)
	{
		// Update the user interface
	}
}
</pre><pre class="brush: objc;">
- (Preferences *) getPreferences
{
	NSDictionary *dict = nil;
	NSData *result = [Networking queryPreferences];
	if (result)
	{
		dict = [self parseData:result];
	}

	return dict;
}
</pre><pre class="brush: objc;">
+ (NSData *) queryPreferences
{
	return [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.something.com/data.json"] returningResponse:nil error:nil];
}
</pre><p>In order to not block the main thread, the developer has to always make sure that displayUserPreferences is called on a secondary thread. While this may sound simple, forgetting to do this is quite easy especially for a developer that didn&#8217;t initially write the code. Another developer might think that getPreferences is a local call and doesn&#8217;t hit the network and therefore call displayUserPreferences on the main thread. This is, of course, a recipe for disaster.</p><p>The second issue isn&#8217;t specific to networking, but has to do with threading. In the above example, the &#8220;Update the user interface&#8221; code under the comment must run on the main thread as user interface calls can/will crash when run on secondary threads. It is far too easy to forget to use performSelectorOnMainThread to run the code on the main thread. Having to keep track of what can and can&#8217;t run on a secondary thread just adds confusion and inevitably will lead to mistakes. A simple call like:</p><pre class="brush: objc;">
[self.tableView reloadData];
</pre><p>run on the secondary thread for networking will cause a crash.</p><p>I&#8217;ve seen both of these issues in code and there really is no excuse for being lazy in writing networking code. Once you write a good networking class, it can be reused over and over; I&#8217;ve used a networking class I wrote a few months ago in 4 or 5 different projects. I wrote it once; tested it extensively and now reusing it is quite simple.</p><p>I&#8217;m tempted to file a radar bug to ask Apple to deprecate the synchronous call, but I know that they won&#8217;t do it. The synchronous networking call screams lazy and should be avoided in my opinion.<br /><hr/>Copyright &copy; 2012 <strong><a href="http://blog.gruby.com">Scott Gruby</a></strong>. The opinions expressed here do not necessarily reflect those of my employer. Please visit this site and use the Amazon link to support it.</p> ]]></content:encoded> <wfw:commentRss>http://blog.gruby.com/2011/05/24/more-pitfalls-to-synchronous-networking/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Authentication security in iOS apps</title><link>http://blog.gruby.com/2011/05/18/authentication-security-in-ios-apps/</link> <comments>http://blog.gruby.com/2011/05/18/authentication-security-in-ios-apps/#comments</comments> <pubDate>Thu, 19 May 2011 02:48:55 +0000</pubDate> <dc:creator>Scott Gruby</dc:creator> <category><![CDATA[Main]]></category> <category><![CDATA[Programming]]></category><guid isPermaLink="false">https://blog.gruby.com/?p=2990</guid> <description><![CDATA[When I read a post that John Gruber wrote today about OAuth in native Twitter apps and how much of a poor user experience it is/will be, I had to dig deeper into the article. On first read of the &#8230; <a href="http://blog.gruby.com/2011/05/18/authentication-security-in-ios-apps/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>When I read a <a href="http://s.gruby.com/rbpr4">post</a> that John Gruber wrote today about <a href="http://oauth.net/">OAuth</a> in native Twitter apps and how much of a poor user experience it is/will be, I had to dig deeper into the article. On first read of the article, I disagreed with him as I thought he missed a very important point about security, but upon re-reading it, he did identify one of the major issues with how OAuth (and other types of service authentication) is done on iOS, in particular.</p><p><cite>Developers can alleviate some of the context switching by using an embedded web view inside their native app for the OAuth authentication handshake, but at that point, why not just use xAuth and simply allow the user to enter their username and password in a native dialog box? So long as you remain within the app, there’s no security advantage for OAuth in an embedded web view over xAuth&#8230;</cite></p><p>This is something that most users are unaware of when entering their credentials in any iOS app. As long as you are in the app, even if the page says Facebook, Twitter, Dropbox, etc. and you&#8217;re not running an app from these companies, the app can capture your username and password. Some companies ship their libraries to developers in a form that doesn&#8217;t let the developer modify the source code, but that offers zero protection from a malicious developer that wants to steal usernames and passwords.</p><p>I&#8217;ve seen one application launch Safari, ask you to login to Facebook and when done, returns you to the app. From a security point of view, this is the ONLY way to ensure that the application doesn&#8217;t capture your credentials (provided that you trust that Safari isn&#8217;t stealing your credentials). Any embedded web view offers no guarantee that the app isn&#8217;t hijacking your credentials as the app can walk the hierarchy of views and grab info; in a kiosk I worked on, we presented web pages, but I modified the web pages before displaying to change the credit card field to a password field to mask the numbers; this type of modification of web data is quite easy when a developer controls the entire app.</p><p>Should you be worried? That all depends. Do you use different passwords for every service? If not, consider using <a href="http://agilebits.com/products/1Password">1Passwd</a>. Yes, it may be a pain to enter the random password on a mobile device, but if some app got access to the password you use on all your sites, the risk is great. Are most developers honest? Yes, but bugs in the code could put your password at risk. Also when I tried out apps for Google Voice, I had some strange feelings about an app, so I ran my iPhone&#8217;s networking through <a href="http://www.charlesproxy.com/">Charles Proxy</a> to see where the app was connecting; it was connecting to a site that wasn&#8217;t Google. I had no idea if my Google Voice password (which is my Google password for email) was going to some lone developer&#8217;s server. Based on the developer&#8217;s posting in various forums, I didn&#8217;t trust his app with my password.</p><p>Should users be inconvenienced by having an app launch Safari, enter credentials and then go back to the app? Personally, as someone a bit paranoid about security, I think it is worth the one time inconvenience (per app). The average user may not think this way. However, if the user was better educated in the app indicating that for security purposes Safari will be launched, that may mitigate the issue.<br /><hr/>Copyright &copy; 2012 <strong><a href="http://blog.gruby.com">Scott Gruby</a></strong>. The opinions expressed here do not necessarily reflect those of my employer. Please visit this site and use the Amazon link to support it.</p> ]]></content:encoded> <wfw:commentRss>http://blog.gruby.com/2011/05/18/authentication-security-in-ios-apps/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Served from: blog.gruby.com @ 2012-02-09 04:01:45 by W3 Total Cache -->
