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)
}
}
| Action | API | Description |
|---|---|---|
| Start download | try storage.downloadContent(mck) | Starts the download. |
| Cancel download | try storage.downloadCancelContent(mck) | Stops the download session. |
| Pause download | No dedicated API | No 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 download | Call try storage.downloadContent(mck) again | - |
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.
| Property | Type | Description |
|---|---|---|
fileSize | long long | Content file size |
downloadSize | long long | Downloaded size |
downloadProgress | NSUInteger | Download progress (0–100) |
downloadStopSize | long long | Size preserved at the point of download pause |
downloaded | BOOL | Whether the download is complete |
downloadStatus | NSInteger | Download progress status code |