제대로 작동하려면 사운드 파일을 다운로드해야하는 앱이 있습니다.NsurlConnection을 사용하여 다운로드를 시작하면 앱이 중단됩니다.
크기가 20Mb 이상인 파일을 비동기 적으로 다운로드하기 위해 NSURLConnection
을 사용하고 있습니다. 다운로드 비율을 추적하기 위해 progressBarView
을 배치했으며 Apple에서 제안한대로 NSUrlConnection
이라는 위임 방법을 사용하고 있습니다.
NSURLRequest *theRequest=[NSURLRequest requestWithURL:soundFileURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20.0];
// create the connection with the request
// and start loading the data
NSURLConnection *theConnection;
theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
//[theConnection cancel];
//[theConnection start];
if (theConnection) {
// Create the NSMutableData that will hold
// the received data
// receivedData is declared as a method instance elsewhere
receivedData=[[NSMutableData data] retain];
} else {
// inform the user that the download could not be made
}
위임 방법
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
[receivedData appendData:data];
}
하고 그래서
... 나는 다운로드를 시작하면, 인터페이스가 때때로 중단하고progressView
뿐만 아니라 중단
.
한 가지 주목할만한 점은 아마도 또 다른 질문입니다. 다운로드가 완료 될 때까지 기다려야하므로 사용자 인터페이스가 비활성화되고 물론 그에게 메시지를 전합니다. 애플이 내 앱을 거부하겠습니까? 내 질문 : 기본적으로 메인 스레드에 NSURLConnectionDelegate
의
추가 활동 표시를 추가하고 다운로드 –