Stop my OS X firewall complaining about a virtualenv python

No matter how many times I click “allow” on this dialog, it still comes back. This is because my python binary is badly signed (I assume something in the virtualenv builder mangles it).

$ codesign -vvvv venv/bin/python
venv/bin/python: invalid signature (code or signature have been modified)
In architecture: i386

I can fix this by signing it myself (I have a developer account. Maybe you can use self-signed certificates? Pass).

$ codesign -f -s "iPhone Developer: Tom Insam" venv/bin/python
venv/bin/python: replacing existing signature

And now the firewall “allow” button will stick.

Flame for the iPhone

I’ve been playing with iPhone development recently, and have ported Flame to it. Well, re-implemented, really – Flame is written in Python and there’s no PyObjC for the iPhone, and nor is there likely to ever be. But Objective-C is getting easier as I get practice, and this app even has a modicum of proper memory management.

This time, the source lives in GitHub/jerakeen as git seems like the cool kid this week and I need the practice. I’d expect it to build and run in the simulator just fine, and it runs on my device, so it’ll run on yours if you know the magic hoops to jump through. It’s possible that this app might actually make it to the App Store at some point, though it’s somewhat niche.. You never know.

Let me know if you have ideas for improvements. For a start, I’d like certain services to be linkable – HTTP servers should open their web page in Mobile Safari if clicked, for instance.

iPhone local web applications

Startlingly, the webkit-based browser on the iPhone supports the HTML 5 client-side storage standard. Alas, you can’t write properly off-line apps because there’s no local HTML/file cache on the phone you can keep files in. You could use the bookmarklet trick I suppose, but I don’t like that one – it’s nasty, and makes development annoying – you have to keep re-syncing things, it’s not terribly easy to upgrade, etc.

I do, however, want to write local apps in a language that’s a little higher-level than Objective-C. It’s nice and all, but I prefer things to be more flexible. The iPhone SDK agreement means that I can’t write my code in a high-level language and ship an interpreter, alas – no iPhone pyobjc for me. But (and this is speculative, I’m not a lawyer, etc etc) as I read the iPhone SDK user agreement, I think you could probably write a pure HTML/JavaScript application, using the webkit local storage engine, and run it in an embedded webkit view as a local iPhone application.

3.3.2. [..] No interpreted code may be downloaded and used in an Application except for code that is interpreted and run by Apple’s Published APIs and built-in interpreter(s).

(emphasis mine)

This means I can have a shippable application, with local storage, but with large bits of logic written in JavaScript. I may even be able to intercept requests for urls and call API functions from Objective-C space, so I can expose location data to the application, for instance.

There are obviously huge disadvantages to writing an app in HTML, but I’d like to try it if only as both a rapid prototying environment for local apps, and a way of giving apps that are already HTML-based some local storage and the ability to be run when away from network.

Unfortunately, I feel that I can see where this could get taken. The spirit of the SDK agreement is clearly that Apple don’t want any way of distributing applications except through the App Store. This exception is in the SDK only because you can’t have an embeddable web browser widget without saying ‘stuff the web browser does is ok’. But if this loophole actually is a loophole, I don’t see what stops me writing a front-end that can download more HTML into the local storage area.

Well, no, actually, I see

3.3.3 Without Apple’s prior written approval, an Application may not provide, unlock or enable additional features or functionality through distribution mechanisms other than the App Store.

..which might cover that one. Maybe I’ll write something like this as an experiment anyway.

Here’s another thought. If I can intercept requests and call Objective-C functions, why do I need the HTML-displaying part of this at all? How introspectable is Obj-C anyway, and can I ship an Objective-JavaScript bridge in my app?

iPhone web application behaviour

The ‘state of the art’ for iPhone apps is a single URL, serving a static page with lots of JavaScript and Ajax. Clicking (touching, whatever) things loads in fragments and changes the page. IUI works like this, Hahlo works like this, the Facebook app works like this (hence IUI‘s behaviour).

To preserve state, normal usage is to use the URL fragment to add bookmarkability and history. And sometimes, this actually works. But given that the point is to pretend to be a native iPhone application, it’s wrong. You should be storing state in cookies.

Justification: Native iPhone apps act like you never quit them. Even if they get closed by the system at some point, they’ll come back to the state you left them in. Bookmarking a rich web application should act the same – I want to bookmark the application, and have it open in the state that I left it, not the state that I bookmarked it in. So you should update the ‘current state’ in a local cookie every time to navigate somewhere, and respect that state when you next visit the application. Combine this with the 1.1.3 firmware’s webclips thing and you can almost pretend to be native.

Which is why I expect the much-anticipated iPhone SDK to be nothing more than ‘local web applications’. Give developers a little bit of local storage (you know, like webkit just got), a way of promoting a bookmark to the home screen (we have that one now) and a way of storing some HTML and JS on the phone, and Jobs can claim he’s given us an SDK. And he’ll be right.

Me? I’d be happy with that. It solves all the sandboxing, security, ‘bring down the network’, etc problems. And it will keep people from jailbreaking the phone trivially. The only alternative I can see is installation of signed apps only, with the iTunes Media Store as the single point of installation. Which would suck more. But there will be howls of outrage.