Here은 실제 문제입니다. UITableView에서 여러 다운로드 진행 상황을 처리하기위한 클래스를 작성하고 싶습니다. 이 클래스를 작성하는 방법을 모릅니다. 누군가가 팁이나 아이디어를 도울 수 있습니까?iOs에서 다운로드 진행 상황을 업데이트하는 dowloader 클래스를 작성하는 방법
0
A
답변
0
볼 그룹은 NSURLRequest 및 NSURLConnection입니다. 전자는 요청 (URL, http 메서드, 매개 변수 등)을 지정하고 후자는 요청을 실행합니다.
상태를 계속 업데이트하려면 (I answered a sketch of this in your other question), 연결에서 도착할 때 데이터 덩어리를 넘겨주는 NSURLConnectionDelegate 프로토콜을 구현해야합니다. 당신이 기대하는 데이터의 양을 알고 있다면, 당신은 내가 이전에 제안 양이 downloadProgress 플로트를 계산하기 위해받은 사용할 수 있습니다
float downloadProgress = [responseData length]/bytesExpected;
여기 SO 일부 nice looking example code을합니다. 당신은
MyLoader.m
@interface MyLoader()
@property (strong, nonatomic) NSMutableDictionary *connections;
@end
@implementation MyLoader
@synthesize connections=_connections; // add a lazy initializer for this, not shown
// make it a singleton
+ (MyLoader *)sharedInstance {
@synchronized(self) {
if (!_sharedInstance) {
_sharedInstance = [[MyLoader alloc] init];
}
}
return _sharedInstance;
}
// you can add a friendlier one that builds the request given a URL, etc.
- (void)startConnectionWithRequest:(NSURLRequest *)request {
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
NSMutableData *responseData = [[NSMutableData alloc] init];
[self.connections setObject:responseData forKey:connection];
}
// now all the delegate methods can be of this form. just like the typical, except they begin with a lookup of the connection and it's associated state
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
NSMutableData *responseData = [self.connections objectForKey:connection];
[responseData appendData:data];
// to help you with the UI question you asked earlier, this is where
// you can announce that download progress is being made
NSNumber *bytesSoFar = [NSNumber numberWithInt:[responseData length]];
NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
[connection URL], @"url", bytesSoFar, @"bytesSoFar", nil];
[[NSNotificationCenter defaultCenter] postNotificationName:@"MyDownloaderDidRecieveData"
object:self userInfo:userInfo];
// the url should let you match this connection to the database object in
// your view controller. if not, you could pass that db object in when you
// start the connection, hang onto it (in the connections dictionary) and
// provide it in userInfo when you post progress
}
0
내가 정확히 할 this 라이브러리를 쓴 ...이 같은 여러 개의 연결을 확장 할 수 있습니다. github 저장소에서 구현을 체크 아웃 할 수 있습니다.
관련 문제
- 1. uiwebview의 진행 상황을 알려주는 방법
- 2. IOS에서 다운로드 진행 비디오 파일을 재생하는 방법
- 3. GeckoFX로 진행 상황을 처리하는 방법
- 4. Android에서 진행 상황을 확인하십시오.
- 5. 프로세스의 진행 상황을 확인하는 방법
- 6. 서비스 진행 상황을 알리는 방법
- 7. 진행 상황을 사용자에게 알리는 방법
- 8. 비동기로 httprequest를 수행하고 응답 다운로드 진행 상황을 표시하는 방법
- 9. Mozilla Firefox에서 파일 다운로드 진행 상황을 표시하는 방법
- 10. delayed_job, 진행 상황을 추적합니다.
- 11. 로컬 서비스에서 진행 상황을 알리기
- 12. BackgroundWorker의 진행 상황을 정기적으로보고합니다.
- 13. DownloadStringAysnc - 진행 상황을 표시하지 않습니다.
- 14. 데이터베이스 진행 상황을 보여주는 진행 표시 줄
- 15. Jquery를 배우는 방법 진행 상황을 애니메이션화 하시겠습니까?
- 16. 소프트웨어 개발 진행 상황을 측정하는 방법
- 17. 작업자 스레드별로 진행 상황을 변경하는 방법
- 18. IO 작업 중 진행 상황을 표시하는 방법
- 19. box.net API를 사용하여 업로드/다운로드 진행 상황을 확인하는 방법은 무엇입니까?
- 20. php 다운로드가 브라우저에서 진행 상황을 표시하지 않습니다.
- 21. Android : 다운로드 진행
- 22. Monitor GZip Java에서 진행 상황을 다운로드하십시오.
- 23. NSURLConnection 다운로드 진행
- 24. iOS에서 병렬 다운로드
- 25. 대화 상자에서 진행 상황을 표시합니다.
- 26. NSProgressIndicator가 진행 상황을 표시하지 않습니다.
- 27. WCF : 클라이언트에서 진행 상황을 보내고받습니다.
- 28. org.eclipse.core.runtime.jobs.Job의 진행 상황을 org.eclipse.swt.widgets.ProgressBar를 사용하여보고합니다.
- 29. SPSS에서 진행 상황을 사용자에게 알립니다.
- 30. 소프트웨어 진행 상황을 보여주는 도구
내 코드에서는 동시에 여러 다운로드를 처리하고 있으며 한 번의 클릭으로 파일 그룹을 다운로드하려고합니다. 그래서 나는 asinetworkqueue를 사용하고있다. 그래서 큐에 대한 downloadp 로스트 대리인을 설정 중입니다. – Mithuzz
여러 번 같은 패턴입니다. 죄송합니다. 귀하의 질문에이 부분을 알리지 않았습니다. 편집 할 것입니다. – danh