Archive for April, 2009

Dr Nic’s ChocTop is a huge help for making Cocoa application DMGs

April 30, 2009

I released my first Cocoa application, a tiny little “menulet” that flips a bit to affect trackpad behavior on Mac laptops, a couple of months ago.  In buildng the DMG, I had to go through a bunch of trial and error to get the background image right.  I downloaded a couple of different DMG tools before I got what I wanted, and still I cannot remember how I did it.

This time around, I tried something new:  Dr Nic’s ChocTop.  I was skeptical at first because of my prior experience with creating DMGs, but this really is an excellent tool for packaging your Cocoa app.

ChocTop doesn’t try to hide hidden files below the fold or anything, so if you have your Finder set to show hidden files, you may want to change that:

defaults write com.apple.finder AppleShowAllFiles FALSE

killall Finder

Here’s my first DMG produced with ChocTop:
DMG produced with ChocTop

System Configuration Framework Reachability

April 30, 2009

While googling today, I couldn’t find a succinct explanation of this for a very common case: being notified of losing/gaining your network connection.  So I’m going to summarize a simple approach here.

If you’re not familiar with all of the SCReachability jargon, there are three important terms:

  • Reachability Target: The host you will test against to see if you can send data.
  • Reachability Callback: The function which will be invoked when your Reachability Target’s reachability changes.
  • Reachability Flags: A collection of bits that describe the reachability of a target.

Prior to 10.4, apparently the only way to check reachability was by polling a Reachability function.  That’s no longer “how we do, yo.”  Instead, the pattern is:

  1. Write a Reachability Callback.
  2. Create your Reachability Target.
  3. Register your Callback for your Target (SCNetworkReachabilitySetCallback).
  4. Schedule your Callback in your run loop (SCNetworkReachabilityScheduleWithRunLoop).
  5. Sit back and watch as your Reachability Callback is invoked when you unplug your network cable (or turn off your AirPort).

In your Callback, you’ll want to check the flags which are passed in.  Be sure you understand how these flags work.  It is not always intuitive (checking kSCNetworkFlagsReachable may not be sufficient for determing whether a host is reachable or not).

To get started, try running the SimpleReach sample app while plugging/un-plugging your network cable.

Finally, don’t forget to clean up your reachability target via SCNetworkReachabilityUnscheduleFromRunLoop and CFRelease.

Kingdom of the Crystal Skull returns in 2012 and we’re all gonna die or something!

April 29, 2009

From “The 2012 Apocalypse — And How to Stop It

Worse yet, the next period of intense solar activity is expected in 2012, and coincides with the presence of an unusually large hole in Earth’s geomagnetic shield. But the report received relatively little attention, perhaps because of 2012’s supernatural connotations. Mayan astronomers supposedly predicted that 2012 would mark the calamitous “birth of a new era.”

Three new things I’ve learned this week

April 23, 2009

I’ve been writing a lot of code lately, which means I’ve had no shortage of “learning opportunities” (or, as some people call them, bugs):

  1. Yesterday I enjoyed learning how to debug an autorelease pool using malloc_history.
  2. Monday I gained a deeper understanding of how Quartz strokes a path and why it would cause your rounded rectangles to become fuzzy at the corners (if you don’t account for the stroke width).
  3. Tuesday I discovered that keeping around a UITableViewCell for resizing calculations can be handy but error-prone.  Hint: if your table view is re-using cells, then your re-sizing calculation code better not depend on the cell’s contents remaining constant between calls.

It’s a Keeper Northeast v1.1 Now Available!

April 20, 2009

Lots of updates for the 2009 season in this version:It's a Keeper - Northeast

  • CT: Fluke regulations for ’09 are finally available!
  • RI: Public hearing scheduled for 4/22/09 on recreational limits for Striped Bass, Fluke, Scup, and Black Sea Bass.
  • ME: Numerous updates for ’09.
  • NY: Fluke regulations for ’09 are now available. Please note that the State of NY has a filed a federal lawsuit against NMFS which could potentially change the 2009 fluke season in NY, depending on the ruling in that case.
  • MA: Numerous updates for ’09, including Fluke, Cod, Sea Bass, Weakfish and Flounder.

A technique for calculating size of UIWebViews

April 16, 2009

One thing that you end up doing often in an iPhone application is calculating text size and resizing labels and their containers.  This is easy to do for plain text that is all the same font because of the extra NSString methods like sizeWithFont:constrainedToSize:.

When you need to use a UIWebView to display text with HTML formatting, though, you cannot rely on these simple text size methods.  Line breaks, bulletted lists, non-visible markup characters would all contribute to making text sizing methods fail.

I had an idea while walking the dog yesterday about how to get around this, and it seems to work pretty well for simple blocks of text with basic HTML formatting.

The gist:

  1. Wrap your HTML formatted text in an enclosing div tag with an ID.
  2. Load it into your UIWebView using loadHTMLString:baseURL:.
  3. Add the webViewDidFinishLoad: delegate method, so you know when the text has been rendered.
  4. In that method, use the UIWebView stringByEvaluatingJavaScriptFromString: method to execute javascript that returns the scrollHeight and/or scrollWidth of the UIWebView.

Voila!  You now have a rough idea of what size that text will render.

If you are resizing the webview based on these results, keep in mind you may need to use some padding to account for the space around your div inside the webview itself.

Omniscience…

April 16, 2009

…means always knowing your friends’ latest status updates:God now on Facebook

Noah’s Ark!

April 14, 2009

Totally arksome!

Noah's Ark

Harvest

April 14, 2009

I’ve been experimenting with some alternatives to my old Ruby scripts for tracking my time lately.  One service I’ve been testing out is called Harvest.  So far, I’ve found it to be easy to use and just the right level of functionality.

One thing it does not provide that my old method of time-tracking did is what I call the show-me-the-money calculation.  This is just the number of hours you’ve billed but not invoiced, and the sum that those hours amount to (in Benjamins).Scythe

Luckily, Harvest has a very simple REST API that gives me access to enough info to make those calculations myself.  So I’m working on a menulet which will “show me the money” all the time…

Animation & Drawing Bugs

April 10, 2009

Twice now I’ve been bitten by the same genus of bug with iPhone implicit animations.  Instead of trying to memorize all of the minute and changing details about each bug, I’ve reduced it to a simple, if broad, praxis:

When your UIKit views draw funny, the first suspect is any animation code operating on those views or their superviews.