Wednesday, May 1, 2013

NSURLResponse expectedContentLength example ios


expectedContentLength

Returns the receiver’s expected content length
- (long long)expectedContentLength
Return Value of [NSURLResponse expectedContentLength]
The receiver’s expected content length, or NSURLResponseUnknownLength if the length can’t be determined.
Discussion of [NSURLResponse expectedContentLength]
Some protocol implementations report the content length as part of the response, but not all protocols guarantee to deliver that amount of data. Clients should be prepared to deal with more or less data.
Example of [NSURLResponse expectedContentLength]
-(void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse    *)response {
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    if([recievedData length]) [ recievedData setLength:0 ];

    download_size =[response expectedContentLength];
}
Example of [NSURLResponse expectedContentLength]
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {

}
-(NSURLRequest *)connection:(NSURLConnection *)connection
        willSendRequest:(NSURLRequest *)request
       redirectResponse:(NSURLResponse *)response {
}
like this:
long long size = [response expectedContentLength];