Mar 012009

I just submitted iDjembe 2.0 to the app store. I decided to change the version number to 2.0 because I did a major rewrite of the audio player code.

For the first version, I just wanted to make something quick that hopefully would cash in on the app craze and make some money. This time I’m serious about making it good.

The major new feature is Virtual Drum Circle, which lets you connect to other players on the local network and broadcast your beats to them.

The major under the hood change is that it now uses OpenAL instead of the simple audio player (which pretty much sucked). I tried several sound APIs including Audio Queue and AVAudioPlayer, but I found that OpenAL is the most straightforward and gives the best performance.

Unfortunately Apple’s iPhone developer documentation doesn’t cover OpenAL, although there are several code samples that use it. I found the best information to be at Ben Britten’s blog and the official OpenAL site.

After some experimentation, I determined the best strategy is to use a pool of OpenAL sources and prepare a buffer for each sound. Instead of using a single source for each sound, when I need to play a sound, I get the next available source, and add the desired sound buffer to it. As a result, it can now play more than one sound at a time and can play the same one repeatedly without a click.

When Safari 4 was released today, a lot of people reported that 1Passsword won’t work with it. Since I rely on 1Password, I was very reluctant to upgrade. The developers of 1Password came up with an easy work around, which must be re-applied with every 1Password update until they officially support Safari 4. I came up with a simple automatic patcher, which you can download here, including full source code.

Nikon has released development kits for many of their newest cameras, including the D90, as well as a NEF (RAW) file decoding library. The SDK lets you write applications that control the camera directly via USB (like Aperture’s tethered mode).

To get any of their SDKs, fill out this form at Nikon’s site.

Jan 202009

I’ve had several reports that swiping no longer works in I Can Has Cheezburger 1.1. A small part of it is that when the image is zoomed, it will not let you swipe to switch images since that same gesture will reposition the enlarged image. Double-tapping to un-zoom will once again let you switch images by swiping.

The real reason is because of how I was detecting a swipe gesture.

In the original version I simply tested for a movement larger than the minimum swipe distance (which was 24 pixels).


float deltaX = fabsf(startTouchPosition.x - currentTouchPosition.x);
float deltaY = fabsf(startTouchPosition.y - currentTouchPosition.y);
// If the swipe tracks correctly.
if (deltaX >= HORIZ_SWIPE_DRAG_MIN)
.... handle swipe action

However, in version 1.1 I also check that the vertical movement is less than the minimum distance.


float deltaX = fabsf(startTouchPosition.x - currentTouchPosition.x);
float deltaY = fabsf(startTouchPosition.y - currentTouchPosition.y);
if (!zoomed && (deltaX >= HORIZ_SWIPE_DRAG_MIN) && (deltaY < = VERT_SWIPE_DRAG_MAX))
.... handle swipe action

I've reverted to the old behavior for the next update, which will support the Cheezburger submission API that isn't ready yet. I may release a small update just for this and a few other tiny fixes rather than wait for the API.

My iPhone development signing certificate expired yesterday. Thankfully I found that creating a new certificate is quick and painless. Luckily I still have my Certificate Signing Request (CSR).

All you really have to do is upload the CSR. If you don’t have it, you’ll have to create a new one by following the instructions in the certificates tab in ADC’s iPhone center.

After uploading the CSR, you’ll have to approve it by clicking the ‘approve’ button in the certificates tab. In a few minutes, the certificate is ready to download.

Thanks to Craig Hockenberry for pointing out that iPhone developer & distribution certificates are beginning to expire. I checked my keychain and found that my developer certificate expires tomorrow and my distribution certificate expires on the 25th. I’m not sure if I still have my original certificate signing request (CSR), so I’ll probably have more work to do.

For any other iPhone developers reading this, open Keychain Access, do a search for ‘iPhone’ and note the expiration dates. Don’t be caught by surprise.

Dec 142008

D90 Video I captured at last night’s tree trimming party, with music added in iMovie.

Lots more photos here.

In an application I’m working on, I display a UIWebView with a navigation bar. I wanted to display the title of the web page in the navigation bar when I load a page, but there doesn’t appear to be any obvious way to do it.

There’s actually a very easy way to get the title (or any other property) of a page in a web view: stringByEvaluatingJavaScriptFromString:.

In this case, I use the delegate method webViewDidFinishLoad to obtain the page title and set the title of the navigation bar,

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    NSString* title = [webView stringByEvaluatingJavaScriptFromString: @"document.title"];
    navbar.title = title;
}

The result looks like this:

iPhone Simulator
Uploaded with plasq‘s Skitch!

Coda is my favorite web development environment on the Mac, combining a syntax-aware editor, a visual CSS editor, and an FTP client that can sync local changes to the web server. Until I read this item at Dra Studio, I had no idea you could add custom books to Coda.

Adding books to Coda is very simple – simply click the ‘+‘ button at the bottom of the Books page and enter the book title, main URL, and a search URL. You can find URLs for some useful books to add at Dra Studio & SitePoint.

I find the WordPress documentation (codex.wordpress.org) especially useful when working on WordPress plugins or themes.

Coda
Uploaded with plasq‘s Skitch!

One of the changes I’m making in the next version of ICanHasCheezburger is improved multi-touch handling. In the current version, I’m only handling left & right swipes to switch to the previous or next images. For the update, I’d like to handle the same gestures as the photo app:

  • Pinch to zoom in & out
  • When zoomed in, drag the image to see different portions
  • When zoomed or moved, double-tap to return to the standard zoom
  • Swipe left & right to move to the next image – but NOT when zoomed in
  • Single tap to toggle toolbar & menu bar

In many cases you can use a UIScrollView, which implements most of those behaviors. For ICHC, I decided to subclass UIImageView to handle touch gestures.
Continue reading »

Making lulz
Uploaded with plasq‘s Skitch!

Sep 282008

I like to check Flickr’s camera finder page every few days to see how popular the D90 is. As I write this, the D90 is ranked 15 of 102 Nikon models. Less than a week ago, it wasn’t even listed. Yesterday it was #19, a jump of 4 places in one day.

Here’s a shot I took today with my 50mm lens at f1.8. I love being able to use auto focus with that lens.

New Orchid

Since the F**KING NDA makes it difficult to find iPhone programming tips & sample code, I thought I’d share this little tidbit.

Sometimes the easiest way to display a help or information screen is a UIWebView. It’s very easy to display the contents of an HTML file stored in the application’s resource bundle.

    NSData *info = [NSData dataWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"info" ofType:@"html"]];
    [webView loadData:info MIMEType:@"text/html" textEncodingName:@"utf8" baseURL:nil];

However, if you have any external links, they will open in the same web view, which you probably don’t want. I found a very nice work-around to have any clicked URLs open in Safari. You’ll need to specify a delegate for your web view that implements the webView:shouldStartLoadWithRequest:navigationType method. The code is very simple.

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    if (navigationType == UIWebViewNavigationTypeLinkClicked) {
        [[UIApplication sharedApplication] openURL: [request URL]];
        return NO;
    }
    return YES;
}

Sep 192008

Kudos to Craig Hockenberry for defying Apple’s F***ING NDA and releasing the source code for an iPhone game, Lights Out, as inspiration for aspiring iPhone developers.

Xcode gives this very informative error message when an iPhone enabled for development is being updated in iTunes.

Very informative XCode error
Uploaded with plasq‘s Skitch!

For the past few months I’ve been working on a server administration application (I can’t go into specifics). It was ported Windows code that included some MFC emulation using old-fashioned Mac APIs such as WaitNextEvent. As expected, it never worked reliably and I was starting to feel defeated by it.

I figured out that the actual server code consisted of self-contained C++ objects that had very little to do with the application code. I ended up throwing away most of the old application code and grafting the server code into a modern Cocoa application using some ObjectiveC++ bridge classes. Once I got it to build, it took less than a day to get it working, and in the process fixed lots of long-standing bugs.

TouchCode is a set of iPhone open source projects that fill in some features that are missing from Cocoa Touch. The most useful part is TouchXML, which is a drop-in replacement for Cocoa’s NSXML* classes.

I was able to get the unmodified ObjectiveFlickr code working by simply doing a global search & replace of NSXMLDocument with CXMLDocument, NSXMLNode with CXMLNode, and NSXMLElement with CXMLElement. The result is less ugly than using NSXMLParser.

For the Official LOLCats application I need to handle RSS feeds, which I found to be exceptionally ugly with NSXMLParser. With TouchXML it’s easy. I can get an array of items with something like this:


NSError *err = nil;
CXMLDocument *doc = [[CXMLDocument alloc]
initWithContentsOfURL: [NSURL URLWithString: @"http://feeds.feedburner.com/myfeed"]
options:0 error: &err];

NSArray *nodes = [doc nodesForXPath: @"//item" error: nil];

I spent the weekend modifying ObjectiveFlickr to work on the iPhone, which was mostly a matter of changing the response handling code that depends on NSXMLDocument. I was pretty much able to plug in my MCFlickrParser class, which I use in LOLCats, to create a NSDictionary structured very much like the XML document.

Yesterday I was informed about FlickrKit, which already works on the iPhone. FlickrKit seems more advanced, but it’s also a lot larger than ObjectiveFlickr. I created simple Flickr browsers using both frameworks. The FlickrKit version is 704k, while the ObjectiveFlickr version is only 148k. I’ve only tried it on the simulator and the performance seems about the same for both.

I will probably stick with OF for this project, since I would like to support Zooomr as well as Flickr and OF already seems to support Zooomr.

Aug 102008

UPDATE: Minutes after I posted this, I got a notice from Apple that the update has been approved and is now ready for sale.

Apple still hasn’t approved my update to LOLCats. Still no response from Apple for the second update, which I feel is pretty urgent, since it reduces the possibility of inappropriate images appearing, which I’ve received several complaints about.

I’m now getting close to another update, which adds Zooomr support.

Meanwhile, I’m working on a second Flickr-related application. I had expected to share a lot of code with LOLCats, but it turns out I’ve only reused one class, my Flickr parser.

For this app, I need to support Flickr authorization, so it seemed easier to rewrite Flickr’s ObjectiveFlickr code, which already supports authorization. However, ObjectiveFlickr depends on XMLDocument, which isn’t available on the iPhone. I’m replacing the response handling code with my Flickr parser class. When it’s finished, I’ll release the Flickr-related code (not the entire app) as open source.

On a fun note, I purposely added the LOLCATS tag to this photo of Midnight to make it to appear in the application. As a result, the number of hits on that photo are about 100x the average for my similar photos.

Midnight watching

Until I started poking around in Flickr’s Objective C code, I didn’t realize that Zooomr supported a variant of Flickr’s API. I found that it’s fairly easy to port code which uses Flickr to Zooomr. In less than an hour, I had LOLCats working with Zooomr. I plan to include Zooomr support in the other iPhone Flickr app I’m working on.

© 2010 /dev/random Suffusion WordPress theme by Sayontan Sinha

/dev/random is Digg proof thanks to caching by WP Super Cache