Archive for the ‘iPhone’ Category

Local Web Apps

Wednesday, April 27th, 2011

I think I’ve finally settled on the architecture that makes the most sense for data collection types of applications for the iPhone. I just do them in HTML and use the webkit control everywhere.

Of course I need access to sqlite and so I’ve found I can add new subclasses of NSURLProtocol to provide handlers to access different parts the local machine’s resources.

The first and most useful one I did works with urls of the format sqlite://database/table?a=&b=&c= where a,b, and c are field names. If this is used with a form that has its method set to POST, then a table that can hold all those fields are created and an insert statement is generated to save the record. The response is a JSON dictionary of the resulting record (done to provide the generated primary key back as well as any set default values).

If it is used with a form whose method is set to GET, then all the mentioned fields are fetched, and the ones that have values are used as filters. The response is again a JSON array of dictionaries. This makes a quickie search form easy, however I also look for a field named sql and if that is present, I just execute that as the query instead. Sometimes only SQL will do.

If the form method is DELETE, then the matching records are deleted. Since responses are JSON, using jquery is a no-brainer.

The entire NSURLProtocol subclass is about two pages of code and works with RAILS style form serialization naming conventions to allow saving/retrieval of hierarchies. It also uses ActiveRecord naming conventions and requires a primary key field of id on each table. The primary key is generated as a guid.

Works great. Dead simple. Don’t even need a server. I will be exploring this architecture more.

Bye bye Three20 Hello ASIHttpRequest

Thursday, February 3rd, 2011

Its been a year? Yeah – pretty sad. But now I have something worth saying.

For the past year I’ve been doing iPhone apps that talk to a server back end. I started with Three20. Seemed like it offered some useful UI widgetry. However eventually I found it was easier to whip up fancy UI using UIWebView so I gave up on the Three20 widgets. I did keep the network piece. But as of today I dumped that too.

The Three20 developers are slow to respond to fixes and the network portion assumes it is always doing http or it has a couple hacks to reference the documents or bundle directories using urls with schemes bundle: and documents:. This might be OK but the way it is done is a hack and general file: urls still don’t work. Plus the TTURLRequest has bugs in generating post bodies that I’ve fixed in my copy but haven’t been adopted despite offering them back.

So that’s enough – ASIHttpRequest seems both lighter in weight and more powerful. It is nearly a drop-in replacement and so far I’m impressed.