Category Archives: Software

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

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).

Update (2023): The link to Yummy’s website has been updated to point to Wandle Software, which didn’t exist at the time of launch.

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 icon ((Not sure what’s wrong with the colours. It looks great on the phone itself, which, presumably, is not colour managed.)) 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 screenshot 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 the 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.

Update (2023): The link to Yummy’s website has been updated to point to Wandle Software, which didn’t exist at the time of launch.

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/lightbox ((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.)). 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” feature ((Thanks to Roman Seibel for figuring this out.))
  7. You’re done

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

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!

GIndent

One thing that really bugs me is badly formatted code. I’ve nearly written a PL/SQL indentation program a number of times, but have never actually? completed it.

But this time it’s different. I figured that most of the pretty printers out there are very poorly written and work only on one particular programming language. However, most languages are very similar to one another. They all have comments, blocks and ‘if’ statements.

Mine may not be much better written — you be the judge of that — but it is generic, having the capability of working with multiple languages.

It’s currently nowhere near complete, so I have uploaded my current development version to Sourceforge. You can check out the latest version here,
but don’t expect it to actually work for you just yet. There’s currently a nearly working HTML formatter and a very incomplete PL/SQL module.