开发者

NSURLConnection and ProgressBar Crash when try to convert to float

开发者 https://www.devze.com 2023-01-19 00:44 出处:网络
i am trying to use progressbar while downloading using NSUrlConnection am missing somthing but dont know what

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 numberWithUns开发者_如何学CignedInteger:[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”.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消