1

ダウンロードする前にファイルサイズを取得する必要があります。プログレスバーの使用

ファイルが 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;
}
4

1 に答える 1