Oct 02

One of the great advantages of the iPhone platform is that it’s a single target to develop for. It doesn’t suffer from the “write once, test everywhere” syndrome of J2ME. But with 2.0, 2.1 and future firmware releases, not to mention rumored tablets and other new touch products, this will change.

The other day I managed to write an application that worked on 2.0 but not 2.1 devices. After some investigation I found that the root cause was a subtle change Apple made in 2.1 without any notification in release notes or in the SDK documentation.

Consider this very common snippet of code:

NSData *webData = [NSData dataWithContentsOfURL:url];

If the url in the above example refers to a file that is gzipped, e.g. www.myserver.com/file.gz, NSData will now (in 2.1) unzip the data automagically. So if your code was expecting to receive a representation of the compressed file, it will now break.

Most browsers will to the gzip/gunzip automagically when a web server sends compressed content. This is done to save bandwidth, improve download speed, and is generally a Good Thing. When the same “feature” is implemented in the SDK and you are not given any control over the behavior, that’s a Bad Thing.

The moral of this story is that you need to test all your code on both 2.0 and 2.1 devices.
 

written by Nick \\ tags:

4 Responses to “Are you testing on both 2.0 and 2.1?”

  1. HTTP GZIP support? - iPhone Dev SDK Forum Says:

    […] GZIP support is built in from firmware 2.1. All you need to do is: NSData *webData = [NSData dataWithContentsOfURL:url]; And if the server sends back gzip content with the right headers, then the resulting NSData will contain the uncompressed data. More information here: Are you testing in both 2.0 and 2.1? […]

  2. Cafer MENDERES Says:

    Hi;
    Can you explain the “if the server sends back gzip content with the right headers”
    please?
    thanks

  3. Nick Says:

    @Cafer: The iPhone sends the HTTP request header “Accept-Encoding: gzip, deflate” to the server. If the server supports gzip compression, it will compress the data and send the HTTP response header “Content-Encoding: gzip” to indicate that the content has been compressed with gzip.

  4. Cafer MENDERES Says:

    thanks for your help Nick….

Leave a Reply