我需要在下载之前获取文件大小。并使用进度条
这是我的代码运行良好,除非文件托管在 Hostmonster 服务器上,否则我想知道错误是什么。
错误如下:[NSConcreteMutableData initWithCapacity:]: 荒谬容量:4294967295,最大大小:2147483648 字节'
这是我的代码
NSURL *url33;
NSNumber *filesize;
NSMutableData *data2;
url33 = [NSURL URLWithString: @ "http://www.nordenmovil.com/enconstruccion.jpg"];
- (void)connection: (NSURLConnection*) connection didReceiveResponse: (NSHTTPURLResponse*) response
{
filesize = [NSNumber numberWithUnsignedInteger:[response expectedContentLength]];
NSLog(@"%@",filesize);
}
- (void)connection:(NSURLConnection *)theConnection didReceiveData:(NSData *)recievedData {
[data2 appendData:recievedData];
if (data2==nil) {
data2 = [[NSMutableData alloc] initWithCapacity:[filesize floatValue]];
}
NSNumber *resourceLength = [NSNumber numberWithUnsignedInteger:[data2 length]]; //MAGIC
float progress = [resourceLength floatValue] / [filesize floatValue];
progressBar.progress = progress;
}