Saturday, July 31, 2010

Downgrading iPhone OS

Yes, sometimes you need to. Like if you have an iPhone 3G and you install OS 4 on it. And you don't like how unresponsive the OS got. Well, here's an excellent how-to. Don't forget the step with RecBoot - it's worth downgrading your phone just to see the message RecBoot gives you when you're done!

Saturday, July 24, 2010

SQLite: Easy as 1 2 3 ...4 (Practically Painless)

Yes, SQLite is an excellent SQL solution for the iPhone.

So, how to add support to a project?

I'm assuming that you have an SQLite database already. If you don't, try SQLite Database Browser. It isn't perfect, but it works well enough, and you can use it to create and edit tables. I also assume that you know how to use what SQLite retrieves in your iPhone project. For a more complete guide, you might try this tutorial, but I like to keep my posts focussed. Eventually I'll take the time to learn the pros and cons of using Core Data - I've been led to believe it can do some of the same things that SQLite can do (it can even write to a file in SQLite format) - but until I understand it better I'll stick with what I know: SQL.

Adding the SQLite Framework to your project 

It's as easy as 1 2 3 ...4...

  1. Right-click on Frameworks
  2. Click Add -> Existing Frameworks
  3. In the drop-down, select Dylibs
  4. Select libsqlite3.0.dlib and click Add
Accessing your SQLite database

I'm using fmdb to access the database (it has an MIT license), rather than write my own object for accessing the db. I've copied over the project into a folder I aptly named "FMDB". From there on it should be calm seas! FMDB even comes with a "fmdb.m" file that can be used to see the code in action.

Saturday, July 10, 2010

Installing Bazaar on Bluehost

I've decided to move my content conversioning system (CVS) off of my local system to I don't have to worry so much about my apartment burning down. I've got a bluehost server, so it seems like a good place to put it. Of course, that also means I have to set it up myself, since bluehost doesn't have a script to do it, and naturally I couldn't find a guide anywhere to do it - so I decided to write one myself.

I'm assuming in this guide that you have access to a brain, and a shell session to your bluehost box. I like to use putty myself, dirt simple. Yes, I'm lazy, so I didn't compile this information into a script - it'd be a great little project for someone!

Grabbing the Source
First thing's first: I'm going to need to install from source, because I don't have access to the CentOS's yum package installer. I grabed the latest stable release, bzr-2.1.2.tar.gz, from https://launchpad.net/bzr/+download. It's nice to know that every release the bzr team has put out is available there for download.

Installing Dependencies
On to the next step: dependencies. The Bazaar install instructions indicate a number of dependencies that I'll go through as needed. Bazaar uses python, and bluehost doesn't permit users to install python eggs in the default location, so there's some prep work required beforehand. You'll need to upload all the files to your bluehost server using ftp cPanel, or just use wget.

     Preparing your PATH (per bluehost instructions)

  1. Add the following to .bashrc (I had to revise "python" to "python2.4":
    1. export PYTHONPATH=$HOME/.local/lib/python2.4/site-packages:$PYTHONPATH
    2. export PYTHONPATH=$HOME/.local/lib64/python2.4/site-packages:$PYTHONPATH
    3. export PYTHONPATH=$HOME/lib/python:$PYTHONPATH
    4. export PYTHONPATH=$HOME/lib64/python:$PYTHONPATH
    5. export PATH=$HOME/.local/bin:$PATH
    6. export PYTHONPATH=$HOME/[path to bzrtools directory, e.g. $HOME/.bazaar/plugins]:$PYTHONPATH
  2. Log off
  3. Log back on
Dependencies: Installing Python Eggs on Bluehost
  1. Un-tar the egg
  2. cd into the egg directory
  3. python setup.py build
  4. python setup.py install --prefix=$HOME/.local
    Dependencies


  • Python >= 2.4
    • python -V yields Python 2.4.3, so I'm good there.
     Eggs (use python -c "import [egg name]" to test installation - no response is good)
Installing Bazaar
And now, finally, run make, then python setup.py install --home $HOME. Kind of anticlimactic, really.ls ~/

bzrTools
To instal bzrTools, simply grab the version that corresponds to your version of bzr, extract it, and copy over the bzrtools dir to the path you set up in the section titled preparing your PATH.

Monday, July 5, 2010

ZipKit: Compress and Extract Zip Files Programatically

My Problem:
Download and store a web page that could have multiple resources embedded into the html (e.g. links to pictures, css files, etc.). Why is this a problem? Because I have discovered that there is no way to save a web page programmatically in the iPhone SDK (at least using the 3.x OS). I could download and save each resource separately, but that means parsing the HTML to find each resource, download the resource, and then replace any absolute URLs with relative URLs in every file. A pretty gnarly task indeed.

The Circumstances:
Fortunately I have one thing on my side: I can dicate how I want the web page to exist. That's pretty huge: for example, I can require that it is packaged into a zip file, so I only need to download one file instead of hunting through the html to figure out what all needs to be downloaded.

The Solution:
A nifty library called ZipKit.

There are a couple of considerations that I will have to experiment with before I am satisfied with this solution:

  • How long does it take to unzip the types of zip files I am expecting?
  • If it does take a significant amount of time, how does that compare to the amount of time saved by downloading a compressed (read smaller) zip file?
  • Would a tar file work better, since it does not compress files - you have the full download time of the uncompressed files, but potentially a faster extraction speed (the OS doesn't have to run through a decompress operation)?
  • Can I read directly from the zip/tar file without extracting the files?
Of course, if someone has a suggestion for a better solution to my problem, I am all ears!