2010-02-05 4 views
0

iPhone 앱에 파일이 얼마나 다운로드되었는지 보여주는 진행률 표시 줄을 보여주고 싶습니다. 나는 IB에서 UIProgressView를 셋업하는 방법을 알고있다. 하지만 그것을 실행하려면 파일 크기 (바이트)와 같은 데이터가 필요합니다. 이러한 기능을 바이트 다운로드 코드 (아래 참조)와 통합하려면 어떻게해야합니까?내 앱에서 다운로드를 위해 UIProgressView를 표시하는 방법은 무엇입니까?

- (void)connection:(NSURLConnection *)theConnection didReceiveData:(NSData *)data 
// A delegate method called by the NSURLConnection as data arrives. We just 
// write the data to the file. 
{ 
#pragma unused(theConnection) 
    NSInteger  dataLength; 
    const uint8_t * dataBytes; 
    NSInteger  bytesWritten; 
    NSInteger  bytesWrittenSoFar; 

    assert(theConnection == self.connection); 

    dataLength = [data length]; 
    dataBytes = [data bytes]; 

    bytesWrittenSoFar = 0; 
    do { 
     bytesWritten = [self.fileStream write:&dataBytes[bytesWrittenSoFar] maxLength:dataLength - bytesWrittenSoFar]; 
     assert(bytesWritten != 0); 
     if (bytesWritten == -1) { 
      [self _stopReceiveWithStatus:@"File write error"]; 
      break; 
     } else { 
      bytesWrittenSoFar += bytesWritten; 

     } 
    } while (bytesWrittenSoFar != dataLength); 
} 

답변

2

ASIHTTPRequest 라이브러리로 전환하면 바이트 단위 진행보기를 표시 할 수 있습니다.

정말 체크 아웃하는 것이 좋습니다. iPhone에서이 작업을 매우 간단하게 만들어 모든 응용 프로그램에 사용합니다. 동기식 및 비동기식 연결을 수행하고 쿠키 및 인증을 처리하며 POST 요청을 매우 간단하게 작성할 수 있습니다. 또한 네트워크 대기열이 내장되어 있습니다.

http://allseeing-i.com/ASIHTTPRequest/

+0

Naaaah ... 나는 내 물건은 이미 다시 가서 물건을 변경 시작 mostly..Don't 싶어를 설정해야합니다. 고마워.하지만 거기에 파일의 크기 (바이트)를 얻을 수있는 방법이 있습니까? 그렇게하면 UIProgressView를 사용할 수 있습니다. – RexOnRoids