Category Archives: Software

Software that I’ve written (or at least started writing).

Giving Back

A few years ago I was very much “into” the whole open source movement. I read LWN (still do, actually). I bought a copy of The Cathedral and the Bazaar.

But one thing I never really did was contribute to open source projects. I never really had much need. They largely did what I wanted and when they didn’t, well, the modifications were too big to consider attempting in my spare time.

And now I have a couple of applications in Apple’s App Store. I get the impression that a lot of apps you see there these days are mainly collections of open source code bundled together with some glue code and some new graphics. I know it sounds bad when you phrase it like that, but I don’t mean it that way. When you’re coding to a deadline and to cost this is a perfectly valid way of doing things.

But neither Yummy nor www.cut are like that. They are almost entirely my own code. Why? Two main reasons.

The first is historical: Yummy was initially developed when the now infamous NDA was in place. Developers couldn’t share code even if they wanted to.

Secondly, I like to minimise external dependencies. The iOS platform changes fast enough as it is without having to wait for other developers to update code as well. Of course, open source means that I could fix it myself but that probably means looking at code I’m not completely familiar with and that takes time. The desire to remove third party code led me to remove AdMob in Yummy Browser and www.cut and replace with Apple’s iAd, even knowing that the fill rate was very low1.

Ultimately, however, there’s too much great code out there to avoid it altogether. The current, shipping version of Yummy has two open source components and I have just released a (tiny) third one.

First is the Facebook Connect SDK. I have not made any modifications to this.

Second is InAppSettingsKit. This some software that duplicates the Settings screen and allows them to be included within the app as well as in the Settings.app. I made some minor fixes so that it works on the iPad (independently fixed and pushed upstream) and I added a “Log in to Facebook” cell. I’m not sure how common a requirement this is likely to be, so I’ve not pushed it back to the maintainers but I have made it available in a separate branch:

InAppSettingsKit

Third is something that should really be included in iOS itself. Apple’s guidelines say that when your app is sent into the background it should close any menus that are open. In “iPhone Speak” these are called UIAlertView (dialog in the middle of the screen) and UIActionSheet (menu from the bottom of the screen).

In addition, the iPad had a further requirement: there should be only one menu open at any given time.

I created UIViewAutoDismiss to help:

UIViewAutoDismiss

This code is inspired by a question and answer on Stackoverflow.

  1. Early indications are that, even with the lower fill rate, income is not vastly different, and this is with only two countries active at the moment with iAds. []

iPhone Dev: Saving State

I see every now and again that Apple needs to make it easier to allow developers to save the state of their application so that they open up exactly as they were when they were shut down.

Obviously I’m all for Apple making my life easy, but that’s not going to happen for a while yet so I thought I’d share how I implemented it in Yummy.

The key is this simple protocol:


@protocol SaveState
- (NSData*) saveState;
- (id) initWithSaveState:(NSData*)data;
@end

This is what I have in my applicationWillTerminate: method:


NSMutableArray* vcList = [NSMutableArray arrayWithCapacity:3];
for (UIViewController* vc in self.navigationController.viewControllers) {
    // Classes that don't implement the SaveState protocol will be ignored
    if ([vc conformsToProtocol:@protocol(SaveState)]) {
        NSArray* state = [NSArray arrayWithObjects:NSStringFromClass([vc class]),
                                                                     [(UIViewController*)vc saveState],
                                                                     nil];
        [vcList addObject:state];
    }
}

This is in the applicationDidFinishLaunching::


for (NSArray* screen in screenList) {
    UIViewController* next =
                [[NSClassFromString([screen objectAtIndex:0]) alloc]
                                   initWithSaveState:([screen count] == 2) ?
                                   [screen objectAtIndex:1] : nil];
    if (next != nil) {
        [[self navigationController] pushViewController:next animated:NO];
        [next release];
    }
}

So a simple example, for a view controller that needed to be remembered but didn’t need to store any extra state, would be:


- (NSData*) saveState {
    return nil;
}
- (id) initWithSaveState:(NSData*)data {
    return [self init];
}

But you can initialise each view controller with anything that can be converted into an NSData. (I picked NSData rather than, say, id because an NSData can always be serialised. Made sense to make that assumption.)

One weakness is that it doesn’t cope with the situation where a modal view is on top but that should be pretty easy to implement if it’s important (it generally isn’t in Yummy).

Yummy: Ready for Sale

Ready for Sale

I nearly posted a rude one-liner on Twitter about it. I was sat here in front of my laptop, browsing iTunes and slightly miffed that I’d submitted my iPhone application a week ago and that there had been no sign of movement since then.

Then I received an email from Apple with the good news. So yes, as I type this I don’t see it, but apparently Yummy is now “ready for sale” and will be making its way to the App Store very shortly. (I assume it’s a gradual process and that some people may be able to see it now.)

How exciting is that?!

Update: Yummy is now on the AppStore (opens in iTunes).

Yummy: Prepare for Launch

Yummy in iTunes Connect

Today is a big day for me. A few minutes ago I uploaded my iPhone application up to Apple’s servers, the first step in making it available to users in iTunes and its App Store.

You possibly have two questions. First: what does it do? Secondly: when will it be available?

I know, I have been deliberately vague when talking about it online. This is partly because I didn’t want my thunder stealing by pre-announcing, but mainly because it’s only been in the last week or so that I’ve been sure that I was going to publish.

You’ll note that I’ve still not described what it does. All I’ll say is take a look at the icon1 and think of the name. And, more importantly, keep an eye on Yummy’s website. I’ll be publishing a series of blogs to tell you what it does and some of the decisions I took to make it.

The second question — when — is pretty much out of my hands. Apple will now, as the screen-shot above tells you, review it and, unless I’ve made any mistakes in the rather complex process, make it available for download. The length of queue is not public so it could be tomorrow or the end of September or, more likely, somewhere in between. Fingers crossed that it’s soon!

It’s taken a lot of effort to get to this point and I’m keen to get it in the hands of users. Many thanks to B for putting up with me during this process and for making the great Yummy icon; my gratitude to A for trying to get beta versions installed (damn that 0xE800001 error); and to everyone else who has offered advice and feedback.

  1. Not sure what wrong with the colours. It looks great on the phone itself which, presumably, is not colour managed. []

Photopress/Lightbox Patch

Ever since I moved over to using the WordPress content management system to host this website I have been using a relatively small number of plugins. One of my most used is Photopress which you can see in use almost everywhere you see a picture.

However, late last year I realised how much one, small part of the functionality irritated me. You could either view a full size picture in a page on its own, but I’d never managed to create a template that worked well for both portrait and landscape images. Or you could have each image pop up in another window. I wasn’t keen on that either.

I eventually decided to “scratch an itch” and implement option number three. I’d found and liked the “zoom” effect provided by the Lightbox JavaScript library, and so decided to use that.

I did offer the patch to the author of Photopress, but I have heard nothing from him so find my changes here.

You’ll need to follow the following few steps to do the same with your own site:

  1. Disable the Photopress plugin if you already have it installed
  2. Download the Lightbox Javascript library and install it on your webserver. I put it in wp-content/lightbox1. Remember where you put it as you’ll need it again in a couple of steps
  3. Download and install the plugin. If you don’t have Photopress, try this full version. If you already have Photopress 0.9.5, you can download either the only file that’s changed or this patch file
  4. Activate the plugin
  5. Go to the Photopress Options screen. Look at the bottom of the screen. Here you can enable/disable the Lightbox effect and point Photopress to the Lightbox Javascript routines
  6. Also make sure that you have switched off the “Link to Album” feature2
  7. You’re done

Please let me know how you get on. Hope you like it!

  1. You’ll need to keep the same directory structure as in the LightBox ZIP file. For example, you should see three directories “css”, “images”
    and “js” Inside the “lightbox” directory on the webserver. []
  2. Thanks to Roman Seibel for figuring this out. []

Mirror

This text is taken from the README and explains what mirror does and why I wrote it:

I think that I must have been looking for the wrong thing. When I restructured my web-site it became difficult to upload changes onto the server. What I needed was a program that copied files to the server. While I could find many programs that mirrored a web-site — copied them from the server — I couldn’t find any to do what I wanted.

Being lazy I started to look at other mirror programs with the intention of modifying them. The best candidate, when I tested it, didn’t actually work (no names!) and others had major creeping featurism. All had restrictive licenses.

So I pulled out ‘Programming Perl’ and started coding my own…

It’s not very big or complex, but it does as it says on the box. And as an added bonus it also downloads, just like all the others.

mirror-1.4.tar.gz

If you find another program that does the same job (better), let me know, I’d be interested to learn whether or not I wasted my time!