Suppose, I am downloading a file of 300 MB using NSURLSessionDownloadTask
or NSURLSessionDataTask
(at present, I don’t know which is the best choice in my case). User quits the App or App suddenly crashed while 250 MB were downloaded. When next time, when user opens the App, I would have to resume downloading from 250 MB.
I have made a demo using NSURLSessionDownloadTask
. But, if we are using NSURLSessionDownloadTask
, we don't have access to the NSURL
of the temporary file until the download is complete (and in didFinishDownloadingToURL
we would move this temporary file to its permanent final location).
I came to know that, I will have to use an NSURLSessionDataTask
rather than a DownloadTask
, then use the delegate method on NSURLSessionDataDelegate
:
- (void)URLSession:(NSURLSession *)session
dataTask:(NSURLSessionDataTask *)dataTask
didReceiveData:(NSData *)data;
This will allow me to access the data as it is received. But, I don’t know how would I manage things now onward. I want a way, so that I can append data in above delegate and write it on disk at some location. Second question, how would I know that the downloading of a data should start from here only (i.e. from 250 MB)
Is it really feasible? Or it is feasible only if the App is in active state?
I am desperate to this question.