다운로드 도구를 작성했습니다. 그것은 NSURLDownload와 함께 잘 작동합니다. 그러나 다운로드를 다시 시작하는 데에는 몇 가지 문제가 있습니다. resumeData는 항상 nil입니다! jDownloader를 사용하여 동일한 파일을 다운로드 할 때 다운로드를 중지하고 다시 시작하면 jDownloader가 다운로드를 다시 시작합니다! 그래서이 파일과 서버로 가능합니다!NSURL 다운로드 resumeData nil
코드 :
- (void)startDownload {
status = @"loading";
NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
urlDownload = [[NSURLDownload alloc] initWithRequest:theRequest delegate:self];
[urlDownload setDeletesFileUponFailure:NO];
if (!urlDownload) {
[self error:@"Failed starting download request!"];
}
}
시험 : "stopWithResumeOption"로로드하는 동안 나는 다운로드를 중지하면
- (IBAction)stopWithResumeOption:(id)sender {
[urlDownload cancel];
NSData *tempData = [urlDownload resumeData];
NSLog(@"%@",tempData);
}
난 항상 nil을 얻을! 내가 뭔가를 놓친 건가요?!
편집 :
resumeData가 반환하는 정보는 무엇입니까? 이미 다운로드 한 데이터의 길이 만 있다면 어쩌면 혼자서이 resumeData를 만들 수 있을까요?! 누구든지 전에 이것을 시도 했습니까?
편집 2 :
여기것은 하나 개의 파일의 응답 헤더 나는 다시 시작하는 것을 시도하고있다 : 심지어의 ETag가 서버에 의해 제공됩니다
{
"Accept-Ranges" = bytes;
"Cache-Control" = "max-age=0";
Connection = "keep-alive";
"Content-Length" = 43346723;
"Content-Type" = "application/pdf";
Date = "Sun, 13 Mar 2011 13:08:44 GMT";
Etag = 1185n;
Pragma = public;
Server = dbws;
"X-Robots-Tag" = "noindex,nofollow";
}
을!
그것을 이런 식으로 할 수있는 기회가된다
- (IBAction) resume:(id)sender {
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
NSString *authHeader = [NSString stringWithFormat:@"bytes=%llu-%llu",bytesReceived, totalBytesToLoad];
[request addValue:authHeader forHTTPHeaderField:@"Range"];
urlDownload = [[NSURLDownload alloc] initWithRequest:request delegate:self];
}
는하지만이 시도에 계속하는 방법을 잘 모르겠어요 ...
URL은 무엇입니까? – falconcreek