Writing Your Own Protocol With NSURLProtocol

iPhone in Dock

I have a native iPhone application in development which requires me to interact with a server that uses a stateful protocol over a persistent connection to transfer messages over the wire. This is definitely not a trivial application to write, even though the UI itself is very simple.

The Problem

Stateful protocols and persistent connections are often interrelated, but not by design. My first problem was to divide the original problem in two: how to manage the persistent connection, and how to handle the underlying protocol so that the stateful aspects did not bubble up throughout the UI.

Continue reading »

What’s In Your Dock: iPhone edition

It's been a while since I've been desparate enough to had a chance to do a nice "what's in your toolbox" kind of post. In honor of the iPhone 3.0 upgrade, and Steve Jobs' liver, let's do an iPhone-toolbox post.

I'm unabashedly happy with my phone, because it's strengths and weaknesses mesh pretty well with my actual needs. It's not that great a phone, but I don't use the phone that much. On the other hand, there's never been a better gizmo for whiling away a long train commute.

So, here's some stuff I use:

Instapaper (free light version, $9.99 pro version currently on sale for $4.99)

Instapaper has probably changed my web reading habits more than any other app since I started using RSS readers. It's so simple that its almost hard to believe how useful it is. When I come across an article on the web I want to save for later, I click a bookmarklet. Later, launching Instapaper on the phone, the article shows up, with the images stripped away, and the text presented in a reader friendly format. (Sometimes you can help Instapaper out by invoking it from the printer-friendly version of a page...)

Using Instapaper has become kind of second nature -- I always have a few articles ready to go. The Pro version adds a few nice features, including control of the display font and the ability to scroll the article by tilting the phone. The tilt-scroll sounds like you'll need to be a gymnast or something to read an article, but in practice it's a super-clean interface for reading long articles and letting the text scroll at your reading speed. Great app.

Birdhouse ($3.99)

Very well designed little app for what seems like a dumb use case -- saving drafts of posts intended for Twitter. I mean, how much do you need to polish that tweet about the ham sandwich you had for lunch, amirite?

But, if you are trying to do a tip a day on Twitter (@railsrx), then having a nice place to store up ideas for future tips is great. The app also works as a slightly structured note-taking app, since it can email it's existing draft population back to you.

Stanza / Kindle (Free)

The two leading general-purpose eBook readers, both of them are easy to use, and manage the task of making text readable on an iPhone. It'd be nice if there was some consistency in formats between the two apps, and also if you could buy books directly from the Kindle App (presumably that's coming).

MLB At Bat ($9.99)

Obviously only if you are a baseball fan, but the app gives you access to live box score and play-by-play data, live audio stream of radio broadcast, video highlights, special goodies like condensed game videos a few hours after games and, plus live video streaming on a currently limited basis. That's a lot of stuff. Add in the fact that the app is pretty enough to have won an Apple Design Award, and it's a pretty fabulous package.

Twitteriffic (Free lite, $3.99 no-ads)

There are something like a zillion Twitter clients on the iPhone at last count, and which one to pick is basically idiosyncratic. It's a mark of how fast iPhone development is going that Twitteriffic 1.0 won an Apple Design Award in 2008 and was completely blown away by newer clients six months later before regaining strong status with the 2.0 release. I find this has a nice blend of features and interface. (Tweetie, which is my desktop client, is also very good on the iPhone).

Of course, this all sounds serious -- the big winners on the iPhone have all been games, there are all kinds of inexpensive, addictive little games I play. Here are a few: Defender Chronicles, The Creeps, Drop 7, Flight Control, Frenzic, Galcon, Peggle, Strategery.

Topics:

5 things I can do with my windows mobile phone that you can’t do with your iPhone

samsung_blackjack2
After playing with my friend's iPhone for awhile, and using the company phone for testing out our iPhone applications, I started to get really jealous of how cool it is, and how uncool my samsung windows mobile phone seems by comparison.
The more I used the iPhone, the more I got upset at my windows phone and started demanding "Why can't I do this on my phone?", and the more I found that there were apps out there that I didn't even know existed, as one of big problems with the windows platform is that its not easy to find good apps.
So here's my take on how to make your windows phone better, and what it can do for now that the iPhone can't do.

Continue reading »

Adopt a non-techie. Help your business team move faster

I've been spending some time with our internal sales and marketing team to hash out some of our goals for the year, and it became quite clear to me that non-developers are on their computers all day long facing some of the same technical challenges we do.

Some of the tasks they have to do:

  • "take the data out of the spreadsheet for last quarter and compare it to this quarter"
  • "gather the bounced emails from our newsletter posting, and update our list, pulling out duplicates"
  • "replace all the names and addresses from our NDA agreement each time it is sent to a new client"
  • "slice and dice google ad-words and google analytics data"

So I've resolved to take some time each week to 'Adopt a non-techie', and help them spend less time 'screwing around with the computer' and more time on the most valuable tasks they do.

In the same way that developers need to be as efficient as possible with the tools they use, Continue reading »

Which Mobile Platform Should You Target - Other Points of View

Our two part series Which Mobile Platform Should You Target - on web apps and on native apps - generated a fair bit of feedback, especially from those targeting cross platform development.

Here are a few other points of view on the subject - there is certainly no shortage of opinions and angles:

What's your take?

Which Mobile Platforms Should You Target? (Part 2)

mobilelogos4In the first installment, we covered the simple case, where your application is really a web app, not really using any device features, without local storage, just pulling data from a web application.  This time, we’ll tackle true native applications.

Continue reading »

Which Mobile Platforms Should You Target? (Part 1)

Major Mobile Platforms Our company gets a lot of requests for mobile application development.  Most of the time the request is for a specific platform like the iPhone or Blackberry, but every so often we get a request for “all major mobile devices.”  That request usually changes when people realize that developing on iPhone, Blackberry, Android, Windows Mobile, Palm, etc. really means developing five or more separate applications.  The next question is usually what platform should they target first. That’s not an easy question to answer, because of the constant changes in the landscape and the type of application in question.  Here’s how we tackle it:
Continue reading »

OCMock: Handling Boolean Return Types with NSValue

iPhone in Dock

Testing your iPhone application, you may at some point in time need to stub a method call whose return type is a boolean (or some scalar value, or C based structure). The way to implement this (as described in a discussion on CocoaDev here) is to wrap the boolean in an NSValue using the OCMOCK_VALUE() macro defined in OCMockRecorder.h.

While this solution technically works, I find that doing this within the test class itself makes the test cases a little less readable along the way. Instead, I found it useful to extend OCMock to do this type of conversion for me, keeping my test code a bit cleaner as a result.

Let's take a look at an example by examining the set up for a simple test case..

Continue reading »

Book Review: Core Animation for Mac OS X and the iPhone


book cover

In Core Animation for Mac OS X and the iPhone, Bill Dudney gives a good introduction to the Core Animation framework and some of the slick ways that you can spice up a Cocoa app for Mac OSX or the iPhone. Its assumed that you know your way around Xcode, and that you know the basics of Cocoa programming. So if you are new to Cocoa you may want to have a copy of Cocoa Programming for Mac OS X handy, but you can get your hands on the code examples from Pragmatic Screencasts if you want to try and work your way through it.

The book gives a fair overview of the Core Animation framework, and helps to get you through some of the less intuitive parts. It quickly walks you through a few different examples of developing animation apps for the mac and then explains the differences and limitations of writing for the iPhone. I would also suggest reading through the apple docs which will help you understand some of the other tools available to you and also read more details on what you are working with.

Its a quick read, coming in at only 200 pages, and a lot of those pages are full-page images. Personally, I was hoping for a more thorough review and examples for the iPhone, and was dissapointed that there are only like 14 pages in the iPhone chapter, and 7 of them are a full page of a single image. (I think that might have something to do with the time the book was written and the state of the NDA for iPhone developers, but still I was disappointed).  You can get the pdf directly from the PragmaticProgrammers site, but you might want to check Amazon too.

Overall, I think the book gives a decent start to some animation concepts, and ways to improve your iPhone apps, but you might want to hold off on getting it now, and work your way through the existing docs and other sites first. I suspect the next generation of docs on this topic will have a much deeper review and will be worth the wait.

Now I’m looking for something that can give me a good overview of using OpenGL for the iPhone or something like Blender or Unity3d.

iPhone SDK: Testing UIApplicationDelegate with OCMock

iPhone in Dock
As I have discussed earlier, you can go very, very far in unit testing your view controllers using the following recipe, without the need to bend over backwards or employ any mocking frameworks:

  1. Initialize the view controller in your setup using initWithNibName:bundle:.
  2. Force the view to initialize by invoking the controller's loadView method within your setUp method.
  3. Write tests to assert dependencies or behavior.

This works well enough for view controllers, but when it comes time to test your application delegate, this simple approach can begin to break down. Unlike UIViewController, your application delegate is only initialized as a by-product of loading the NIB. Thus, to get this code under test I find OCMock particularly useful.

I show an example unit test below, and discuss how I approached the problem..

Continue reading »

iPhone SDK: Cache Policy & Cookie Handling in NSURLRequest

I recently ran into an issue building an app which hit an existing (protected) website. Passing credentials along with each request, responses at first appeared to be cached, even after the user credentials changed from within the iPhone app. In sorting through this issue, it gave me a chance to get a bit more familiar with NSURLRequest, and NSURLRequestCachePolicy. As I later found, however, my problem turned out to be cookie-related..

Continue reading »

Topics: , ,

Category and UI changes on Pathfinder blogs

If you read one or more of the Pathfinder blogs in our web interface, you may have noticed some tweaks to our navigation and top-level categories. Our goal in making these changes was to help different audiences drill down to the specific content that interests them. Instead of just a few top-level categories, we now boast around 20, though many posts appear in multiple categories. To subscribe via RSS to any specific category - or to our entire feed - just visit our Feeds page.

Topics:

PureMVC, Spanning the Platform Spectrum?

PureMVCAt Pathfinder we do a fair amount of desktop style development -- iPhone/Cocoa, WebForms, Swing -- and web application development -- Grails, Rails, JSP, ASP.NET, etc., etc.. In the last two years we, like a lot of other software development shops, have experienced a convergence in our efforts. The web is coming to the desktop in the form of Air and the Desktop is coming to the web in the form of RIA's. Now web MVC, which used to be a pretty benign pattern mostly concerned with app flow and validation, is starting to resemble desktop MVC, which has to deal with document-centric models and long lived views and all of the plumbing that requires.

So we recently had a powwow between all the different parties to talk about MVC and this convergence. With the exception of the insufferable Mac and iPhone developers and their disgustingly mature Cocoa framework, we all agreed it would be nice to have an application level MVC framework for each platform. We also agreed that Swing is a great example of what happens when the vendor doesn't provide such a thing -- spaghetti code that relies on component level MVC and hard wiring at the application level. There are a few MVC frameworks for Swing, such as TikeSwing and Spring Rich Client (soon to be superseded by Spring Desktop), but for every Swing app that has this sort of design, there are hundreds that are just a mess.
Continue reading »

Push Button Phones and the Limits of User Testing

I loved this mental_floss blog blog item showing user testing from 1960 of the layout for a push-button phone. (Though I'd be interested to know where mental_floss got the data...) By now we're all used to the layout, and even used to the fact that the phone and calculators have almost directly opposite layouts.

One other thing about the mental_floss article -- the writer suggests that mechanical calculators were around long before this user test. This is true, but as far as I can tell, those calculators did not use the 3x3 layout. I don't think the 3x3 layout became standard on calculators until after 1960.

That detail out of the way, the phone testing data is interesting, both for diagrams of the 18 semi-final designs. Some of those designs are clearly the result of a fevered brainstorm session -- a cross, two diagonal rows, or a circle with the zero in the middle.

Continue reading »

Topics:

iPhone: Using Pre-processor Directives for Device Testing

iPhone in Dock
Updated. (see comments below)

There may be cases where a certain setting needs to be tweaked based on whether you test on the device or simulator. It took me a while to find the pre-processor directive to detect whether or not the current build targets the iPhone device or the simulator, but with a bit of searching through the GTM code, I found everything I needed in "TargetConditionals.h". An obvious place, in retrospect, but I wasn't able to find this information easily elsewhere on the web, so I mention it here in case you find it useful.

Here's an example of how I've used it:

#if TARGET_CPU_ARM
#if TARGET_IPHONE_SIMULATOR
	// Device will hit external server over cell network
	NSString const *ROOT_URL = @"http://www.external-site.com";
#else
	// Simulator will hit local server over LAN
	NSString const *ROOT_URL = @"http://localhost:8667";
#endif

This kind of tweaking is particularly important when the device itself can not participate on the local network, but needs to access some kind of external environment (or proxy server). Conversely, targeting the simulator to use a local 'development' server is often faster when deploying and debugging issues in your application, particularly if you are developing the server component in tandem.

Another example involved certain audio playback features which work fine on the device, but run into hiccups running on the simulator. Since in this case the functionality is not critical to test, I ignore it in the simulator.

Topics: , ,

About Pathfinder

Follow the Blog

    Get a monthly update on best practices for delivering successful software.

    Subscribe via email

      

    Subscribe via RSS      RSS icon

Topics

Search

WordPress

Comments about this site: info@pathf.com