我有這些方法來處理下載NSMutableData initWithCapacity荒謬能力?
但是存在當初始化NSMutableData
NSNumber *filesize;
NSMutableData *data;
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
filesize = [NSNumber numberWithUnsignedInteger:[response expectedContentLength]];
}
- (void)connection:(NSURLConnection *)theConnection didReceiveData:(NSData *)recievedData {
if (data==nil) {
data = [[NSMutableData alloc] initWithCapacity:[filesize floatValue]];
}
[data appendData:recievedData];
NSNumber *resourceLength = [NSNumber numberWithUnsignedInteger:[data length]]; //MAGIC
float progress = [resourceLength floatValue]/[filesize floatValue];
progressBar.progress = progress;
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error "
message:@" " delegate:self cancelButtonTitle: @"OK"
otherButtonTitles:nil];
[alertView show];
connection1=nil;
[connection1 cancel];
}
- (void)connectionDidFinishLoading:(NSURLConnection*)theConnection {
}
在這裏產生的誤差的誤差
數據= [[NSMutableData的alloc] initWithCapacity:[文件大小的floatValue] ]。
[NSConcreteMutableData initWithCapacity:]:荒謬的能力:4294967295,最大尺寸:2147483648個字節
不應該是'initWithCapacity:[filesize unsignedIntValue]'? –
我嘗試,但我仍然標記相同的錯誤。我可以做什麼? – Fabio
查看@科多的徹底答案。 –