Reputation: 644
I'am using URLSessionDataTask
to download videos and play them (I need caching so I'am using the
func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data)
to manually handle the data and provide them to AVAssetResourceLoader
).
in order to do disk caching I must save the downloaded data to disk (when terminating the app) , so that when the user open the app again I can continue downloading the data .
I noticed that it doesn't have a downloadTask(withResumeData:)
like constructor (constructor of URLSessionDownloadTask
which pretty much does that same think , but it doesn't have the func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data)
function :D ) .
now how can I combine these two ?
thank you and sorry for the long post
Upvotes: 1
Views: 578
Reputation: 1417
You should use the Range
header in the request. But you may use it only if the server informs you that it accept range request by Accept-Ranges
response header.
So, if server supports loading from offset You need to add downloaded part offset as header when creating URLRequest
For more info see the Range header specification in HTTP RFC 2616.
Upvotes: 1