Skip to main content

3. Content Download

Content download via the Kollus SDK always proceeds through two steps. First, content metadata is loaded from the URL to obtain the media content key (mediaContentKey, mck) for device verification, and then the actual file download begins based on that key.

All example code in this document is based on the official sample app kollus_player_ios.


Download flow

extension StorageManager {

// Step 1: Load content metadata (synchronous)
public func loadContentURL(URL urlString: String,
completion: @escaping (Error?, String) -> Void) {
do {
let mck = try storage.loadContentURL(urlString)
completion(nil, mck)
} catch {
completion(error, error.localizedDescription)
}
}

// Step 2: Start actual download based on media content key
func startDownloadContent(mediaContentKey: String) {
do {
try storage.downloadContent(mediaContentKey)
} catch {
print(error.localizedDescription)
}
}
}

The loadContentURL method registers content metadata in the SDK's persistent storage and returns the mediaContentKey. Even if the same URL is called multiple times, the returned mediaContentKey remains the same.


Duplicate download check

Use the checkContentURL method to check whether the same URL is already registered in the download list before initiating a new download.

func checkIsDownloadContent(url: String,
completion: @escaping (Bool, KollusContent?) -> Void) {
DispatchQueue.global().async { [unowned self] in
do {
let mck = try storage.checkContentURL(url)
let list = storage.contents() as! [KollusContent]
if let match = list.first(where: { $0.mediaContentKey == mck }) {
DispatchQueue.main.async { completion(true, match) }
} else {
DispatchQueue.main.async { completion(false, nil) }
}
} catch {
DispatchQueue.main.async { completion(false, nil) }
}
}
}

Difference between loadContentURL and checkContentURL

  • loadContentURL: Entry point for a new download (registers new content information)
  • checkContentURL: Matches against existing download history (returns an error if an unregistered URL is passed)

Download cancellation/pause/resume control policy

func cancelDownloadContent(mediaContentKey: String) {
do {
try storage.downloadCancelContent(mediaContentKey)
} catch {
print(error.localizedDescription)
}
}
ActionAPIDescription
Start downloadtry storage.downloadContent(mck)Starts the download.
Cancel downloadtry storage.downloadCancelContent(mck)Stops the download session.
Pause downloadNo dedicated APINo explicit pause API is provided, so cancel with downloadCancelContent and restart. The SDK may internally preserve some data, but in general you should assume the download restarts from the beginning.
Resume downloadCall try storage.downloadContent(mck) again-
Sample application control model

The official sample app does not implement separate pause and resume UI components, and instead adopts a cancel and restart approach.


Track download progress

Real-time download progress is tracked by referencing the properties of the KollusContent instance injected into the delegate callback kollusStorage(_:downloadContent:error:). For more details, refer to the 8. Download Events/Callbacks document.

PropertyTypeDescription
fileSizelong longContent file size
downloadSizelong longDownloaded size
downloadProgressNSUIntegerDownload progress (0–100)
downloadStopSizelong longSize preserved at the point of download pause
downloadedBOOLWhether the download is complete
downloadStatusNSIntegerDownload progress status code