views:

25

answers:

1

Hi Guys

i am trying to use progressbar while downloading using NSUrlConnection

am missing somthing but dont know what

see my code

in my .h i have

NSMutableData *receivedData;

    NSNumber  *FileSize;

which i use to calculate a precent for progressbar

in my .m

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response  

{   
    [receivedData setLength:0];

    FileSize = [NSNumber numberWithLongLong:[response expectedContentLength]];
}

and

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data

{

    [receivedData appendData:data];

    NSNumber *resourceLength = [NSNumber numberWithUnsignedInteger:[receivedData length]];
    NSLog(@"resourceData length: %d ", [resourceLength intValue]);


    NSNumber *progress = [NSNumber numberWithFloat:([resourceLength floatValue] / [FileSize floatValue])];
    updateProgressBar.progress = [progress floatValue];
}

When its reach the line with FileSize float its crash

2010-10-05 22:32:19.924 Quran[2067:207] resourceData length: 1090 Program received signal: “EXC_BAD_ACCESS”.

A: 

I believe that FileSize = [NSNumber numberWithLongLong:[response expectedContentLength]]; is giving you an autoreleased NSNumber that you need to retain somewhere. Maybe you are doing that somewhere else in the code, but that is a probable place you could be getting an EXC_BAD_ACCESS.

Jud Stephenson
Yes i think Thats right , i try NSLog(@"TotalFileSize : %@",FileSize); and i got the EXC_BAD_ACCESS how i can retain it
BoSoud
You could try `[FileSize retain]` after you create it.
Jud Stephenson
Thanks its work now your answer is really help and save me time
BoSoud