views:

350

answers:

0

One of my view needs a big JSON file for tableview. I use gzip in HTTP request, but want to be sure of size.

The problem: How to measure size before and after ungzip? or how to know how strong gzip is?

This my code sample:

NSURL *url=[NSURL URLWithString:urlWithDate];
 NSMutableURLRequest *urlR=[NSMutableURLRequest requestWithURL:url
                                                               cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                          timeoutInterval:20.0];
 [urlR setValue:@"gzip" forHTTPHeaderField:@"Accept-Encoding"];


 NSHTTPURLResponse *response;
 NSError *error;
 NSData *dataFromServer = [NSURLConnection sendSynchronousRequest:urlR 
                                                           returningResponse:&response 
                                                                          error:&error];

 NSLog([[response allHeaderFields] description]);
 NSLog(@"%d", [response expectedContentLength]);
 NSString *stringToParse = [[NSString alloc] initWithData:dataFromServer encoding:NSUTF8StringEncoding];
 NSLog(@"%d / %d", [dataFromServer length], [stringToParse length] );

Any advise how to improve "files download" is appreciated. "sendSynchronousRequest" is used for simplicity.