As I’ve promised in the previous post, I’ve started working on my first iPhone application, the Blip.pl client, which I’ve given an extremely creative name, xBlip :) (why “x”? that’s simple, because “i”, “m” and “a” were taken, “i” even twice :).
A few screenshots from the current version:
It took me whole Saturday and Sunday to get it to this state… Of course, it’s not that complicated, I’m just stupid :> The most difficult part was not the GUI, but connecting to the web service and communicating with it. Some problems I’ve ran into:
- I had to encode login and password with Base64 for HTTP Basic authentication, but there’s no class for this in standard Cocoa. I used code that I’ve found on the CocoaDev wiki.
- I needed a JSON parser for parsing responses from the server. I used the BSJSONAdditions library, because it had the most liberal license.
- Then I had to fix a few things in the parser, because it was unable to parse a string if it contained “\/” or encoded non-ASCII characters.
- I’ve tripped up a few times on the memory management. I remember all the rules very well, because I’ve read about it several times, but it’s just hard to switch your mind to allocating and releasing after having used garbage collection for so many years :) I’ve learned two general rules here:
- Look at the console, every time you start the application. If anything goes wrong, see if you’re getting an exception info there. Most of the time, you can find there a name of the method that caused the error, and if you’re lucky you’ll know immediately what needs to be fixed.
- If you’re getting a completely ridiculous and meaningful error, which shows you cryptic C function names from the depths of ObjC runtime and lots of assembler code – check your memory management. Almost always this means that you’ve released or autoreleased something that shouldn’t have been released.
- At one point, Cocoa (NSURLConnection, specifically) seems to handle HTTP cache in exactly the opposite way than it should. If I tell it to ignore local and remote cache (NSURLRequest
Reload Ignoring Local And Remote Cache Data) 1), it returns cached results, and if I tell it to ignore just the local cache (NSURLRequest Reload Ignoring Local Cache Data), I get fresh results. I don’t know if this is a bug or if I just don’t understand this…
- I also couldn’t figure out why the login dialog doesn’t appear when I call its controller using
presentModalViewController:animated:. It turned out that the solution was to move the call from
viewDidLoadin the main controller to
viewDidAppear:. I’m guessing that probably at the moment when a view is loaded, but not displayed, it doesn’t execute such UI actions like
presentModalViewControllerand just ignores them silently.
Ok, enough complaining, here’s the code: http://github.com/jsuder/xblip. I’ve decided to use GPL v2 as the license – mainly because I kind of don’t feel comfortable with the thought of someone taking that code and making a closed/paid application out of it… And I didn’t want to use GPL v3, because I’ve read that it’s a bit unclear whether the way App Store works isn’t in conflict with GPL v3 (because you can’t just download the code and run it on your phone, you have to pay Apple first…).
I’ve also decided to extract the backend part (called “ObjectiveBlip”) from the application – it’s all in one tree right now, but later I would like to develop that part into a reusable framework that anyone can use to access Blip API from Objective C, in any kind of application. After all, it’s a huge waste of time to write that part from scratch every time. This part is released under Beerware license written by Poul-Henning Kamp – it’s like MIT, only much shorter (4 lines) :) I hate it that with most open source licenses you have to write many pages of text just to say “you can do whatever you want with this, just keep my name in the comment”…
Plans for future versions of xBlip: save settings and current state to files, work on the dashboard look & feel to make it into something pretty, rewrite the ObjectiveBlip engine (right now it’s not very extensible and will get too messy if I just add new features without refactoring first). Then add new features and screens, like a user view or tag view. Add some unit tests. And maybe upload to App Store someday… :)
1) This almost beat the record – it’s just one character shorter than NSManaged