cleanUpExpiredTemporaryFiles:start:progress:completion:
Clean Up Expired Temporary Files
cleanUpExpiredTemporaryFiles:start:progress:completion: is an instance method of the SUDRT protocol. It is used to periodically maintain the mini-game runtime environment by cleaning up stale files generated by downloads, caching, or runtime. By setting a time threshold, developers can balance the trade-off between "loading speed" (keeping the cache) and "storage space" (freeing up capacity).
Method Declaration
objectivec
/**
* Cleans up expired temporary files.
* @param keepTimeInMinute File retention duration (unit: minutes). Files created/accessed earlier than this time are considered expired.
* @param start Callback when the task starts.
* @param progress Progress callback during task execution, providing the path of the currently processed file and error information.
* @param completion Callback after the entire task completes.
*/
- (void)cleanUpExpiredTemporaryFiles:(NSInteger)keepTimeInMinute
start:(nullable void (^)(void))start
progress:(nullable void (^)(NSString *path, NSError * _Nullable error))progress
completion:(nullable void (^)(NSError * _Nullable error))completion;Parameters
| Parameter | Type | Description |
|---|---|---|
| keepTimeInMinute | NSInteger | Expiration threshold: For example, passing 1440 cleans up files older than 24 hours. |
| start | Block | Start hook: Used to display a "Cleaning..." loading state in the UI. |
| progress | Block | Streaming progress: Triggered each time a file is successfully deleted or a permission issue is encountered. |
| completion | Block | End hook: Used to close the cleanup animation or report the cleanup result. |
Runtime Behavior
- Disk traversal: The engine scans all subdirectories under the
SUDRT_KEY_RUNTIME_STORAGE_PATH_CACHEpath. - Time comparison: It checks each file's "last modified time" or "creation time" and computes the difference against the current system time.
- Atomic deletion: Files that meet the criteria are physically deleted; this process is irreversible.
- IO control: This task is typically executed on a background thread to avoid blocking the App's main thread (UI thread).
Code Example
Perform cleanup work during idle time after the App launches:
objectivec
// Clean up temporary caches older than 3 days (4320 minutes)
[self.sdkInstance cleanUpExpiredTemporaryFiles:4320
start:^{
NSLog(@"[SUD] Starting disk space cleanup...");
}
progress:^(NSString *path, NSError *error) {
if (error) {
NSLog(@"[SUD] Cleanup failed: %@, reason: %@", path, error.localizedDescription);
} else {
NSLog(@"[SUD] Deleted stale file: %@", path);
}
}
completion:^(NSError *error) {
if (!error) {
NSLog(@"[SUD] Disk cleanup task completed successfully!");
}
}];Notes
- Frequency recommendation: Frequent calls are not recommended. Typically, triggering it once each time the App launches, or when the user's storage space is detected to be below 200MB, is sufficient.
- Avoid during sessions: If the user is in an intense game session, be sure to avoid calling this method, or call
cancelCleanUpto interrupt it, to avoid IO jitter that causes frame drops in the game. - Whitelist protection: The SDK internally protects the necessary resource packages required by the running game automatically. This method mainly targets temporarily downloaded images, logs, and no-longer-used WPK extraction copies.
