Downloads a HLS (m3u8 file format) to the user's device
- Download, pause, resume and cancel a download task
Declare a set of cancelable objects to subcribe to a Combine publisher
var cancelables = Set<AnyCancellable>()
Subscribe to the file status
let hlsFile = HLSFile(url: URL(string: "https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8")!)
hlsFile.fileStatusPublisher.sink { status in
print("Offline match status: \(status)")
}
.store(in: &cancelables)
hlsFile.download()
You can check whether the file is being download as below
hlsFile.download { isDownloading in
print("File is downloading \(isDownloading)")
}
hlsFile.pause()
hlsFile.resume()
hlsFile.cancel()
At the time of writting this library, the above functions do NOT work on simulator. You would get an unknown error below.
Error: The operation couldn’t be completed. (NSURLErrorDomain error -1.)
It will work fine on the real device.