Yogendra Patel Yogendra Patel - 1 year ago 52
iOS Question

ResumeData getting nil when using downloadTaskWithRequest

If I'm using this below code

aDownloadTask = [self.backgroundSession downloadTaskWithURL:aRemoteURL];

Desc of above code:

When I started download by using downloadTaskWithURL It’s return expectedContentLength negative(-1) But that time resume data getting perfectly.

Another one is
For solved above problem I'm using this below code

NSMutableURLRequest *aURLRequest = nil;
aURLRequest = [[NSMutableURLRequest alloc] initWithURL:aRemoteURL cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60.0];
[aURLRequest setHTTPMethod:@"POST"];
[aURLRequest setValue:@"identity" forHTTPHeaderField:@"Accept-Encoding"];

aDownloadTask=[self.backgroundSession downloadTaskWithRequest:aURLRequest];

Desc of above code:
Using above code expectedContentLength getting perfectly. But issue is the when pause downloading resume data nil every time.

Thats why my downloading start from beginning and not from that point when I pause.

Thanks in advance

Answer Source

Please , remove this below line from your code and try. Your resume data will getting perfectly.

[aURLRequest setHTTPMethod:@"POST"];