An example of using AVAssetDownloadTask in Swift to download HLS content to disk for offline playback in iOS devices.
This sample was primarily created in response to this StackOverflow question with regards to a bug in AVAssetDownloadDelegate in iOS 12 and below.
The issue is that the AVAssetDownloadDelegate callbacks do not seem to fire after the app returns to the foreground when coming from the background.
The download seems to continue, however the progress does not get updated. The solution that seems to work for now is to:
- Subscribe to the
UIApplication.willEnterForegroundNotificationnotification - Check if the device is running iOS 12 and below as the app is returns to the foreground
- If it does,
canceland thenresumethe download task with the url of location on the iOS device where the file was partially downloaded
This solution seems to reset the delegate and all the AVAssetDownloadDelegate callbacks seem to fire again.