Download 更新下载进度条--NSURLConnectionDataDelegate didReceiveData只调用一次

Download 更新下载进度条--NSURLConnectionDataDelegate didReceiveData只调用一次,download,uiprogressview,nsurlconnectiondelegate,Download,Uiprogressview,Nsurlconnectiondelegate,我正在尝试下载1-2Mb的小PDF文件,最多可能是5MB。我正在处理SelectionViewController.m类,它有一个名为progressBar的UIProgressView,它还实现了NSURLConnectionDataDelegate协议 有趣的是,我的进度条突然从0.0变为1.0。我想慢慢地增加它,这样看起来就好了 这是我的密码: -(void)downloadPDFToMyDocumentsFrom:(NSString*) PDFUrl filename:(NSSt

我正在尝试下载1-2Mb的小PDF文件,最多可能是5MB。我正在处理SelectionViewController.m类,它有一个名为progressBar的UIProgressView,它还实现了NSURLConnectionDataDelegate协议

有趣的是,我的进度条突然从0.0变为1.0。我想慢慢地增加它,这样看起来就好了

这是我的密码:

    -(void)downloadPDFToMyDocumentsFrom:(NSString*) PDFUrl filename:(NSString *) title {

    NSURL *url = [[NSURL alloc] initWithString:PDFUrl];
    NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];

    urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];

    NSLog(@"%@", self);

    fileName = [title stringByAppendingPathExtension:@"pdf"];
    filePath = [[SearchFeed pathToDocuments] stringByAppendingPathComponent:fileName];

}



 //handling incoming data
 -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)recievedData{

     if(self.data == nil)
     {
        self.data = [[NSMutableData alloc] initWithCapacity:2048];
     }

     [self.data appendData:recievedData];

     NSNumber *resourceLength = [NSNumber numberWithUnsignedInteger:[self.data length]];

     float progress = [resourceLength floatValue] /[fileLength floatValue];
     self.progressBar.progress = progress;

}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
    long length = [response expectedContentLength];
    fileLength = [NSNumber numberWithUnsignedInteger:length];
    //lastProgress = 0.0;
    //currentLength = 0.0;
    NSLog(@"%f ------------------------------------------------------- is the fileLength", [fileLength floatValue]);
}

    //handling connection progress

-(void)connectionDidFinishLoading:(NSURLConnection *)connection{
    //WRITE code to set the progress bar to 1.0
    //self.progressBar.progress = 1.0;
    // [fileStream close];
    [self.data writeToFile:filePath atomically:YES];

    //[listFileAtPath:self.filePath];
    connection = nil;
    NSLog(@"%f %f-------------------------------------------- Finished Loading ", lastProgress, [fileLength floatValue]);
}
我放了一些NSLog语句来帮助我调试,它看起来像是一次下载完

以下是所有NSLog的输出:

2013-09-05 20:30:04.856 Revista[63246:c07] <SelectionViewController: 0x7180000>
2013-09-05 20:30:04.859 Revista[63246:c07] 63561.000000 ------------------------------------------------------- is the fileLength
2013-09-05 20:30:04.861 Revista[63246:c07] 0.000000 63561.000000-------------------------------------------- Finished Loading 
2013-09-05 20:30:04.856修订版[63246:c07]
2013-09-05 20:30:04.859 Revista[63246:c07]63561.000000-----------------------------------------------------是文件长度
2013-09-05 20:30:04.861 Revista[63246:c07]0.000000 63561.000000-----------------------------------------已完成装载

你们有没有办法让它分块下载,让进度条顺利运行

没关系,我的网络太快了!这就是为什么我看不到正在进行的下载,因为下载速度很快

感谢康卡斯特