What is the best way to update downloaded HLS files in iOS app?

151 views Asked by At

I'm working on an iOS app. I implemented downloading HLS video files logic. I use AVAssetDownloadURLSession, AVAggregateAssetDownloadTask, URLSessionConfiguration.background for it.

I need to implement the logic to update HLS files if they were updated on the server. Is it possible to do this with NSURLRequest.CachePolicy? Or are there other ways to do this? Any help is appreciated.

Session configuration:

private let assetSessionConfiguration: URLSessionConfiguration = {
    let configurationIdentifier = Bundle.main.bundleIdentifier ?? "identifier"
    let configuration = URLSessionConfiguration.background(withIdentifier: configurationIdentifier)
    configuration.networkServiceType = .video
    configuration.requestCachePolicy = .useProtocolCachePolicy
    if #available(iOS 13.0, *) {
        configuration.allowsExpensiveNetworkAccess = true
    }

    if #available(iOS 13.0, *) {
        let memoryMBAmount = 10
        let diskMBAmount = 2048
        configuration.urlCache = URLCache(memoryCapacity: memoryMBAmount * 1024 * 1024, diskCapacity: diskMBAmount * 1024 * 1024, directory: CustomURL)
    } else {
        configuration.urlCache = URLCache.shared
    }

    return configuration
}()
1

There are 1 answers

4
M. LeRouge On BEST ANSWER

One way to do that is to set the cache-control HTTP header on your master playlist response.