4. Download List Management
Explains how to query and manage content data registered in the SDK storage by status. Unlike Android, the iOS SDK retrieves the data source managed by the SDK without local DB persistence, and directly filters it at the app layer to build in-progress/completed/recent download UI lists.
All example code in this document is based on the official sample app kollus_player_ios.
Retrieve the full content list
func contents() -> [KollusContent] {
return storage.contents() as! [KollusContent]
}
The storage.contents() method returns the original array containing all KollusContent objects managed by the SDK (downloading/completed/failed/sample, etc.).
Use this original array and filter it by purpose as shown in the examples below.
Retrieve the list of content currently downloading
From the full list, filter only content whose download is not yet complete (progress < 1) and whose type is currently downloading, to build the in-progress list.
func getDownloadList() -> [KollusContent] {
let contentsList = contents()
return contentsList.filter { content in
let progress = CGFloat(content.downloadSize) / CGFloat(content.fileSize)
return (progress < 1 && content.contentType == .downloading)
|| (progress < 1 && content.contentType == .adaptiveDownload)
}
}
Retrieve the list of completed downloads
From the full list, filter only content where a standard download is complete or an Adaptive download progress is at 100%, to build the completed list.
func getCompletedList() -> [KollusContent] {
return contents().filter { c in
(c.contentType == .downloading && c.downloaded)
|| (c.contentType == .adaptiveDownload && c.downloadProgress == 100)
}
}
Retrieve the recent download list (within 7 days)
From content whose download is fully complete, extract only content whose completion date and time is within 7 days of the current time.
func getRecentlyAddedFileList() -> [KollusContent] {
let now = Date().toLocalTime()
return contents().filter { c in
guard (c.contentType == .downloading && c.downloaded)
|| (c.contentType == .adaptiveDownload && c.downloadProgress == 100)
else { return false }
let downloadedDate = KollusUtil.integerToDate(int: c.downloadedTime)
return downloadedDate.daysBetween(date: now) <= 7
}
}
The downloadedTime property returns an integer timestamp (epoch seconds) of the moment the download was completed.
You can easily convert it using the KollusUtil.integerToDate(int:) method included in the official sample app.
Download status flags
The KollusContentType specifications referenced when classifying content objects and determining their status.
| Category | Description |
|---|---|
.downloading | Standard download content (includes both in-progress and completed state objects; branch using the downloaded property) |
.adaptiveDownload | Adaptive HLS download content (branch using the downloadProgress property) |
.sample | Sample content (recommended to preserve when performing a full delete) |
Criteria for determining download completion
The criteria for determining completion differ depending on the download method. Refer to the rules below to branch between in-progress and completed states.
- Standard download (
.downloading): Complete whendownloaded == true - Adaptive HLS download (
.adaptiveDownload): Complete whendownloadProgress == 100
Display list and custom sorting
The official sample app provides a guide model that sorts the content list by content title, download completion date and time, or file size according to the user's settings.
list.sort {
if $0.fileType != $1.fileType {
return $0.fileType > $1.fileType // Sort folders above regular files at all times
}
switch PreferenceManager.sortOrder { // Branch based on user-configured sort order
case Sort.name.rawValue:
return $0.title < $1.title
case Sort.downloadedTime.rawValue:
return $0.downloadedTime > $1.downloadedTime
default:
return $0.fileSize > $1.fileSize
}
}