preDownloadGame:completion:
Pre-download Game (by Game ID)
This method asynchronously starts a game package download task via the game's unique identifier (Game ID). It automatically handles the process of obtaining the download URL from the cloud, verifying file integrity, and storing the package in the local cache. Pre-downloading can significantly reduce the waiting time when users enter the game.
Method Declaration
objectivec
/**
Pre-download game package using game ID.
@param gameID The unique identifier of the game.
@param completion Called when the download task finishes or fails.
@return An instance of id<SUDOPGameTask> to control or track the task.
*/
+ (id<SUDOPGameTask>)preDownloadGame:(nonnull NSString *)gameID
completion:(nullable SUDOPCompletion)completion;Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| gameID | NSString * | Yes | The unique identifier of the game. |
| completion | SUDOPCompletion | No | Task-finished callback. On success, error is nil; on failure, error contains the specific reason. |
Return Value
Returns an object conforming to the id<SUDOPGameTask> protocol. Developers can cancel the task (cancel) or obtain the task's unique identifier through this object.
Runtime Behavior
- Automatic Authorization: The SDK first obtains the necessary download credentials based on
gameID. - Resumable Download: The SDK usually supports resumable-download logic; if part of the content was downloaded before, it resumes from the last position.
- Cache Strategy: After the download completes, resources are saved in a private cache directory managed by the SDK, and subsequent
startGamecalls load from the cache first.
Example Code
objectivec
[SUDOP preDownloadGame:@"game_abc_123" completions:nil];Notes
- Network Environment: It is recommended to check the network status before calling, or handle errors caused by network interruptions in the callback.
- Repeated Triggering: If a task for the same
gameIDis already running, calling again may return the same Task instance or directly attach to the current task's listener. - Storage Space: Ensure the device has sufficient disk space; otherwise, the download will fail due to an IO error.
