ダウンロードを処理するこれらのメソッドがあります
しかし、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 {
}
ここでエラーが発生します
data = [[NSMutableData alloc] initWithCapacity:[filesize floatValue]];
[NSConcreteMutableData initWithCapacity:]: 不条理な容量: 4294967295、最大サイズ: 2147483648 バイト'