I use Apple Mail Rules for many things. They help me organize and flag incoming messages, which I find very useful. Recently however I came across a problem trying to implement a rule which is supposed to run a script as its action. The AppleScript code was never executing. Attempts to seek solutions via Twitter, StackOverflow, and mailing lists all yielded no working results. I finally got it working, and thought I’d share how it’s done.
Let’s say you’re making HTTP requests and handling responses as we described last time. Parsing the results is usually pretty easy, but what happens when you have a large blob of data, be it XML or JSON or whatever? Any lengthly processing on the main thread, more than a couple hundred milliseconds, will introduce a noticeable hiccup in the UI. Adding a worker thread would help, but perhaps the easiest method is to use the non-blocking NSOperationQueue. With NSOperationQueue you simply package up the work to be done into an NSOperation instance and add it to the queue.
It’s common for iPhone apps to need to make HTTP requests and receive results in either JSON or XML format. There are several excellent full-featured tools ( ASIHTTPRequest, RestKit, etc.) to help you with this task, but sometimes all you need is NSURLConnection. NSURLConnection is a simple class that provides easy to use high-level asynchronous request/response handling. I’ll describe a simple wrapper I’ve been using to make it easy to handle multiple requests easily.
When using NSURLConnection there are only a couple of things to deal with. Unless you are using the synchronous version (not recommended) you will typically set up an object, such as your application delegate or a view controller, as a delegate to receive the NSURLConnectionDelegate callbacks. The main delegate message you need to handle are connection:didFailWithError:, connection:didReceiveData:, and connectionDidFinishLoading:.
One potential issue you face here is using a single object as delegate for multiple connections. Then your delegate message handlers will become messy as they attempt to determine which response goes with which request, etc. Now instead consider creating a utility class with just two public methods, like this:
And finally, the standard delegate methods for NSURLConnection are hidden inside the myConnectionController implementation. These should be familiar if you’ve ever used NSURLConnection directly:
This week marks the 3rd anniversary of the App Store launch. It sounds, and feels like a lifetime ago. It’s sometimes hard to remember how “unconnected” our lives were before the iPhone, but I can say that prior to June of 2007 I absolutely hated every cell phone I owned. There was the Qualcomm clunker, the Motorola junker, the Samsung clamshell, etc. More often than not the phone was merely a device to slap the carrier’s label on to. People got a “verizon phone,” or an “at&t phone” if you lived in the U.S. We were, and still are, captives of the telcos, but that’s starting to change finally.
The new shiny is here. At the annual WWDC recently, Apple unveiled three widely-anticipated new products. This year it was all about software, so hardware announcements will have to come later. In the keynote Steve Jobs mentioned OS X Lion, iOS 5, and iCloud. If you’re an iOS or Mac developer these changes will have a huge impact on you in the next few months. I’m not going to go into much detail about the announcements, but you should definitely check out the keynote if you haven’t seen it yet.
The annual pilgrimage to San Francisco is underway this week. I figure I’ve attended about a dozen in the past 21 years. All have indeed been awesome. Many long-time attendees seem to have mastered the week-long partying and a few have even published “survival guides.” My goal is not to get as many free drinks as I can, or to stay awake during the late-afternoon sessions. I’m here to see old friends, make new ones, and absorb the latest installment of greatness from Apple. I came prepared with questions, code problems, and and open mind about what’s next for iOS and OS X. Seeing a live Stevenote will be a bonus.
I ran into an odd issue the other day and spent a little time getting to the bottom of it. It turns out I wasn’t taking good care of my Xcode project’s library search paths. Here’s what I had to do about it and why you might care. Note this problem has likely been lurking in my project for some months, and may have caused other unintended consequences.
Like pay-to-play or in-app ads, prompting for a rating is controversial in that some developers frown upon it. Free apps tend to have an average 3 star rating. People rarely bother to go back to the App Store to rate an app. There’s always a small minority that will go out of their way to provide negative reviews. So why not solicit positive feedback by providing a reminder to rate the game? In my opinion, there’s nothing overtly annoying or obnoxious about presenting an alert view that can easily be dismissed.
We are sad to see that AGON Online is shutting down at the end of June. A couple of years ago when I was researching services for online leaderboards, I decided to use AGON for two of our holiday games. This was an easy choice on my part, because at the time Open Feint and Scoreloop were a little rough around the edges. Both have matured fantastically, of course, and with the advent of Game Center, the folks at Aptocore (makers of AGON Online) have felt the inevitable squeeze of the bigger competitors.
Soon we’ll be heading to Seattle for the biannual VTM iPhone conference. This two day event will be held the weekend April 9-10, with an optional third day of seminars the day before. This will be my third Voices That Matter conference, and I’m looking forward to some great sessions and seeing old friends again. I’m also very interested in the hands-on cocos2d seminar with Rod Strougo and Ray Wenderlich on Friday. For those new to Cocoa and Objective-C there’s also a full-day session with the Big Nerd Ranch guys Aaron Hillegass and Joe Conway.