I am working on a browser application and i want to track how much internet data is consumed when a web page is load. I am using this method to calculate data received by iOS application.
- (void)connectionDidFinishLoading:(NSURLConnection *)connection{
NSLog(@"Did Receive Data %i", [resourceData length]);
length += [resourceData length];
NSLog(@"Data in MB: %.3f",(length/(1024*1024)));
}
I am opening http://www.google.com in iOS simulator and same browser application for android. When page load completes iOS application show 20KB data used but android application shows 280KB data used. In android there is a class to get data used in an active session, that class name is TrafficStats. I search a lot but in iOS, i don't find any class or method that have similar.
I also try this code when webViewDidFinishLoading called to get actual data consumed by webView to load that page.
-(void)webViewDidFinishLoad:(UIWebView *)webView{
NSString* script = @"document.documentElement.outerHTML.length";
length += [[webBrowser stringByEvaluatingJavaScriptFromString:script] floatValue];
NSLog(@"Data in MB: %.3f",(length/(1024*1024)));
//[self performSelectorOnMainThread:@selector(dataUsedByApp) withObject:nil waitUntilDone:5.0];
}
But this is also not accurate because it doesn't calculate the size of images and size is calculated with @"document.documentElement.outerHTML.length".
Please help me on this. :)