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.
February 23rd, 2009 at 11:58
[…] 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? […]
May 5th, 2010 at 00:50
Hi;
Can you explain the “if the server sends back gzip content with the right headers”
please?
thanks
May 6th, 2010 at 15:11
@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.
May 10th, 2010 at 00:56
thanks for your help Nick….