7. Delete Downloaded Content
This document is a machine-translated draft and is currently undergoing review. Some content may be inaccurate or differ from the original Korean version. For the most precise information, refer to the Korean documentation.
Describes how to safely delete downloaded content files and streaming cache data stored in offline storage, and how to free up disk space.
All example code in this document is based on the official sample app kollus_player_ios.
Delete a single content
Use the removeContent method to simultaneously clean up content files stored in the memory buffer and on the local disk.
func removeContent(mediaContentsKey: String) {
do {
try storage.removeContent(mediaContentsKey)
} catch {
print(error.localizedDescription)
}
}
Delete all downloaded content
Iterates through all downloaded content objects obtained via a full list query and runs the removeContent process consecutively.
The official sample app preserves objects with the sample content (.sample) property for testing convenience, and deletes only the remaining downloaded files.
func removeAllDownloadContents() {
for content in storage.contents() as! [KollusContent] {
if content.contentType == .sample {
continue // Preserve sample content.
}
removeContent(mediaContentsKey: content.mediaContentKey)
}
}
Delete streaming cache
Cleans up only the cache data temporarily accumulated inside the device during streaming playback (online environment), not downloaded files.
You can calculate the total streaming cache size accumulated so far in advance by referring to the storage.cacheDataSize property. You can use this to implement a UI that shows the cache size to users on a settings screen or similar.
func deleteCacheDatas() {
try? storage.removeCache()
}
Automatic cleanup of expired content
There are cases where the SDK automatically deletes media files in the background in response to DRM callbacks kind: 2, kind: 3.
When a forced deletion signal is detected, the SDK has already deleted the local files.
Because the SDK deletes the files first and then notifies the app after the fact, the app layer does not need to call a separate deletion API. Instead, simply analyze the response properties within the injected delegate (kollusStorage(_:request:json:error:)) callback and refresh the UI list only.
Exception handling when device storage is insufficient
When the remaining disk space on the device is insufficient, the SDK does not forcibly clean up other completed files or free up space on its own. It is recommended to use a defensive code pattern that checks capacity before starting a download and prompts the user to take action.
- Pre-check capacity limit: Just before starting a download, compare
DiskStatus.freeDiskSpaceInByteswith the content file size. If space is insufficient, reject the download and display a "Insufficient device storage space" alert dialog. - Provide cleanup options: For user convenience, it is recommended to provide menu options on the screen such as "Clean up files not viewed in the last 30 days" or "Bulk delete watched content."