05 Aug How to Optimize iOS App Performance using GZIP
Gzip is a popular method of compressing files for faster network transfers. But not many are aware that it can be implemented on iOS apps too. Here’s how it works:
Supported OS & SDK Versions
● Supported build target – iOS 8.4/MacOS 10.10 (Xcode 6.4, Apple LLVM compiler 6.1)
● Earliest supported deployment target – iOS 7.0/MacOS 10.9
● Earliest compatible deployment target – iOS 4.3/MacOS 10.6
All the GZIP methods are thread safe. Hence, it’s easy to say that these methods can be called from multiple threads concurrently.
It’s pretty easy. Just drag the category files (test files & assets not needed) into your project & import the header file into any class where you wish to use the GZIP functionality. No need to include the libz.dylib, as GZIP locates it automatically at runtime.
- (NSData *)gzippedDataWithCompressionLevel:(float)level;
In this method, the compression level is a floating point value between 0.0 & 1.0. In case a negative value is supplied, the default compression level is around 0.7.
- (NSData *)gzippedData;
This is equivalent to calling gzippedDataWithCompressionLeve
- (NSData *)gunzippedData;
It unzips the compressed data using deflate algorithm & returns the output.
This method returns ‘Yes’ if the data is gzip-encoded.
Quick upload/download of data from server to client & vice versa.
Have you used GZIP Compression before? Did I leave anything out? Share your experiences/feedback/suggestions below.