2013-09-06 3 views
2

작은 PDF 파일을 다운로드하려고합니다. 1 ~ 2MB는 최대 5MB 정도입니다. SelectionViewController.m 클래스에서 progressBar라는 UIProgressView가 있고 NSURLConnectionDataDelegate 프로토콜도 구현하고 있습니다.다운로드 진행률 표시 줄 업데이트 중 - NSURLConnectionDataDelegate didReceiveData가 한 번만 호출됩니다.

재미있는 점은 진행률 막대가 갑자기 0.0에서 1.0으로 바뀌는 것입니다. 이것을 천천히 증가 시켜서 멋지게 보이고 싶습니다. 나는 나에게 디버깅하는 데 도움이되는 몇 가지 NSLog 문을 넣어 가지고와 그것의 모든 한 번에 다운로드하는 것 같다

-(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]); 
} 

:

여기 내 코드입니다.

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 

너희들이 조각 다운로드 진행률 표시 줄이 원활하게 움직일 수 있도록하는 방법에 어떤 생각을 가지고 있습니까 : 여기

모든 NSLog의 출력입니까?

답변

0

내 네트워크가 너무 빠르다! 그것이 빠른 번개이므로 다운로드가 진행중인 것을 볼 수없는 이유입니다.

컴캐스트 덕분에!